SlideShare ist ein Scribd-Unternehmen logo
1 von 137
Downloaden Sie, um offline zu lesen













 




 













































































































[CreateAssetMenu]

public class TankConfig : ScriptableObject

{

public float speed;

public float rotate;

}

public class TankController : MonoBehaviour

{

[SerializeField] TankConfig config;



public void Update ()

{

var v = Input.GetAxis ("Vertical1");

var x = Input.GetAxis ("Horizontal1");

if (v != 0)

GetComponent<NavMeshAgent> ().Move (transform.forward * (v * config.speed));

if (x != 0)

transform.localRotation *= Quaternion.AngleAxis (x * config.rotate, Vector3.up);

}

}

public class TankController : MonoBehaviour

{

[SerializeField] TankAIBase ai;



public void Update ()

{

ai.Do(gameObject);

}

}
public abstract class TankAIBase : ScriptableObject

{

public virtual void Do (GameObject obj) { }

}
[CreateAssetMenu]

public class TanksStand : TankAIBase{}

[CreateAssetMenu]

public class TankRotate : TankAIBase

{

public float rotate = 2;



public override void Do (GameObject obj)

{

obj.transform.localRotation *= Quaternion.AngleAxis (rotate, Vector3.up);

}

}

[CreateAssetMenu]

public class TankMove : TankAIBase

{

public float speed = 0.5f;



public override void Do (GameObject obj)

{

obj.GetComponent<NavMeshAgent>().Move(obj.transform.forward * speed);

}

}
public class TankController : MonoBehaviour

{

public void Move(float accel)

{

GetComponent<NavMeshAgent>().Move(transform.forward * (accel * 0.2f));

}

}
[CreateAssetMenu]

public class TankData : ScriptableObject

{

public TankController tankController{get; set;}



public void Up () { tankController.Move(5); }

public void Down () { tankController.Move(-5); }

}

[DefaultExecutionOrder (-100)]

public class EventTriggerBehaviour : MonoBehaviour

{

[SerializeField]

UnityEvent onAwake = new UnityEvent (), onDestroy = new UnityEvent ();



void Awake ()

{

onAwake.Invoke ();

}



void OnDestroy ()

{

onDestroy.Invoke ();

}

}



[CreateAssetMenu]

public class Config : ScriptableObject

{

public Item[] items = new Item[0];



[System.Serializable]

public class Item

{

public Texture texture;

public int param;

public string name;

}

}
[CustomEditor (typeof(Config))]

public class ConfigEditor : Editor

{

public override void OnInspectorGUI ()

{

base.OnInspectorGUI();

var config = (Config)target;
// レイアウト記述
}
}
[CreateAssetMenu]

public class Config : ScriptableObject

{

public Item[] items = new Item[0];



[System.Serializable]

public class Item

{

[PreviewTexture]

public Texture texture;

[Range(0, 100)]

public int param;

public string name;

}

}
[CreateAssetMenu]

public class Data : ScriptableObject

{

[SerializeField] int count;



void OnValidate ()

{

count = Mathf.Clamp (count, 0, 99);

}

}








public class param1_importer : AssetPostprocessor
{ 

static void OnPostprocessAllAssets (
string[] importedAssets, string[] deletedAssets, string[] movedAssets,
string[] movedFromAssetPaths)
{
ExcelItem data = (ExcelItem)AssetDatabase.LoadAssetAtPath (exportPath, typeof(ExcelItem));

if (data == null) {

data = ScriptableObject.CreateInstance<ExcelItem> ();

AssetDatabase.CreateAsset ((ScriptableObject)data, exportPath);

}
// インポート処理
ScriptableObject obj = AssetDatabase.LoadAssetAtPath (
exportPath, typeof(ScriptableObject)) as ScriptableObject;
EditorUtility.SetDirty (obj);
}
}
[CreateAssetMenu]

public class SampleDictionary : ScriptableObject, ISerializationCallbackReceiver

{

const string path = "item.json";



public Item item = new Item ();



public void OnBeforeSerialize ()

{

var json = JsonUtility.ToJson (item);

File.WriteAllText (path, json);

}



public void OnAfterDeserialize ()

{

if (File.Exists (path)) {

var json = File.ReadAllText (path); 

JsonUtility.FromJsonOverwrite (json, item);

}

}

}


public abstract class ResettableScriptableObject : ScriptableObject

{

public abstract void Reset ();

}

[CreateAssetMenu]

public class SaveData : ResettableScriptableObject

{
public int count = 0;


public override void Reset ()

{
//初期化コード
count = 0;
}
}

public class DataResetter : MonoBehaviour

{

public ResettableScriptableObject[] resettableScriptableObjects;



private void Awake ()

{

for (int i = 0; i < resettableScriptableObjects.Length; i++)

{

resettableScriptableObjects[i].Reset ();

}

}

}

public abstract class ResettableScriptableObject : ScriptableObject

{

[SerializeField] int _count = 0;

public int count{get; set;}



void OnEnable()

{

count = _count;

}

}

public class ResettableScriptableObject : ScriptableObject 

{

protected virtual void OnEnable()

{

#if UNITY_EDITOR

if( EditorApplication.isPlayingOrWillChangePlaymode == true ){

UnityEditor.EditorApplication.playModeStateChanged += (state) => {

if( EditorApplication.isPlayingOrWillChangePlaymode == false) {

Resources.UnloadAsset(this);

}

} ;

}

#endif

}

}

[CreateAssetMenu]

public class Config : ResettableScriptableObject

{

public float _count;

}





































【Unity】Scriptable object 入門と活用例
【Unity】Scriptable object 入門と活用例
【Unity】Scriptable object 入門と活用例

Weitere ähnliche Inhalte

Was ist angesagt?

【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
Unity Technologies Japan K.K.
 
【Unity道場スペシャル 2017京都】スマホゲーム開発者なら知っておくべきチートのリスク&対策
【Unity道場スペシャル 2017京都】スマホゲーム開発者なら知っておくべきチートのリスク&対策【Unity道場スペシャル 2017京都】スマホゲーム開発者なら知っておくべきチートのリスク&対策
【Unity道場スペシャル 2017京都】スマホゲーム開発者なら知っておくべきチートのリスク&対策
Unity Technologies Japan K.K.
 
ピクサー USD 入門 新たなコンテンツパイプラインを構築する
ピクサー USD 入門 新たなコンテンツパイプラインを構築するピクサー USD 入門 新たなコンテンツパイプラインを構築する
ピクサー USD 入門 新たなコンテンツパイプラインを構築する
Takahito Tejima
 

Was ist angesagt? (20)

Observableで非同期処理
Observableで非同期処理Observableで非同期処理
Observableで非同期処理
 
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
 
UnrealBuildTool勉強会まとめ
UnrealBuildTool勉強会まとめUnrealBuildTool勉強会まとめ
UnrealBuildTool勉強会まとめ
 
アプリ起動時間高速化 ~推測するな、計測せよ~
アプリ起動時間高速化 ~推測するな、計測せよ~アプリ起動時間高速化 ~推測するな、計測せよ~
アプリ起動時間高速化 ~推測するな、計測せよ~
 
Unityでパフォーマンスの良いUIを作る為のTips
Unityでパフォーマンスの良いUIを作る為のTipsUnityでパフォーマンスの良いUIを作る為のTips
Unityでパフォーマンスの良いUIを作る為のTips
 
バイキング流UE4活用術 ~BPとお別れするまでの18ヶ月~
バイキング流UE4活用術 ~BPとお別れするまでの18ヶ月~バイキング流UE4活用術 ~BPとお別れするまでの18ヶ月~
バイキング流UE4活用術 ~BPとお別れするまでの18ヶ月~
 
ObserverパターンからはじめるUniRx
ObserverパターンからはじめるUniRx ObserverパターンからはじめるUniRx
ObserverパターンからはじめるUniRx
 
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
【Unite Tokyo 2018 Training Day】C#JobSystem & ECSでCPUを極限まで使い倒そう ~C# JobSystem 編~
 
インタフェース完全に理解した
インタフェース完全に理解したインタフェース完全に理解した
インタフェース完全に理解した
 
【Unite Tokyo 2018】さては非同期だなオメー!async/await完全に理解しよう
【Unite Tokyo 2018】さては非同期だなオメー!async/await完全に理解しよう【Unite Tokyo 2018】さては非同期だなオメー!async/await完全に理解しよう
【Unite Tokyo 2018】さては非同期だなオメー!async/await完全に理解しよう
 
Unityではじめるオープンワールド制作 エンジニア編
Unityではじめるオープンワールド制作 エンジニア編Unityではじめるオープンワールド制作 エンジニア編
Unityではじめるオープンワールド制作 エンジニア編
 
猫でも分かるUMG
猫でも分かるUMG猫でも分かるUMG
猫でも分かるUMG
 
【Unity】 Behavior TreeでAIを作る
 【Unity】 Behavior TreeでAIを作る 【Unity】 Behavior TreeでAIを作る
【Unity】 Behavior TreeでAIを作る
 
テストを書こう、Unity編
テストを書こう、Unity編テストを書こう、Unity編
テストを書こう、Unity編
 
MVPパターンによる設計アプローチ「あなたのアプリ報連相できてますか」
MVPパターンによる設計アプローチ「あなたのアプリ報連相できてますか」MVPパターンによる設計アプローチ「あなたのアプリ報連相できてますか」
MVPパターンによる設計アプローチ「あなたのアプリ報連相できてますか」
 
【Unity道場スペシャル 2017京都】スマホゲーム開発者なら知っておくべきチートのリスク&対策
【Unity道場スペシャル 2017京都】スマホゲーム開発者なら知っておくべきチートのリスク&対策【Unity道場スペシャル 2017京都】スマホゲーム開発者なら知っておくべきチートのリスク&対策
【Unity道場スペシャル 2017京都】スマホゲーム開発者なら知っておくべきチートのリスク&対策
 
ピクサー USD 入門 新たなコンテンツパイプラインを構築する
ピクサー USD 入門 新たなコンテンツパイプラインを構築するピクサー USD 入門 新たなコンテンツパイプラインを構築する
ピクサー USD 入門 新たなコンテンツパイプラインを構築する
 
【Unity道場スペシャル 2017京都】最適化をする前に覚えておきたい技術
【Unity道場スペシャル 2017京都】最適化をする前に覚えておきたい技術【Unity道場スペシャル 2017京都】最適化をする前に覚えておきたい技術
【Unity道場スペシャル 2017京都】最適化をする前に覚えておきたい技術
 
未来のプログラミング技術をUnityで -UniRx-
未来のプログラミング技術をUnityで -UniRx-未来のプログラミング技術をUnityで -UniRx-
未来のプログラミング技術をUnityで -UniRx-
 
UniRxことはじめ
UniRxことはじめUniRxことはじめ
UniRxことはじめ
 

Ähnlich wie 【Unity】Scriptable object 入門と活用例

EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
Heiko Behrens
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
Kiyotaka Oku
 
Android Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdfAndroid Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdf
feelinggift
 

Ähnlich wie 【Unity】Scriptable object 入門と活用例 (20)

EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
MBL301 Data Persistence to Amazon Dynamodb for Mobile Apps - AWS re: Invent 2012
 
Blending Culture in Twitter Client
Blending Culture in Twitter ClientBlending Culture in Twitter Client
Blending Culture in Twitter Client
 
Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++
 
Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationUsing Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdfAPI 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET Application
 
Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
Android Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdfAndroid Studio Assignment HelpCan someone who is familiar with And.pdf
Android Studio Assignment HelpCan someone who is familiar with And.pdf
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
(Rx).NET' way of async programming (.NET summit 2017 Belarus)
(Rx).NET' way of async programming (.NET summit 2017 Belarus)(Rx).NET' way of async programming (.NET summit 2017 Belarus)
(Rx).NET' way of async programming (.NET summit 2017 Belarus)
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
Deep dive into new ASP.NET MVC 4 Features
Deep dive into new ASP.NET MVC 4 Features Deep dive into new ASP.NET MVC 4 Features
Deep dive into new ASP.NET MVC 4 Features
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
662305 11
662305 11662305 11
662305 11
 
Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)Mary Had a Little λ (QCon)
Mary Had a Little λ (QCon)
 
OBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .pptOBJECTS IN Object Oriented Programming .ppt
OBJECTS IN Object Oriented Programming .ppt
 
mobl
moblmobl
mobl
 

Mehr von Unity Technologies Japan K.K.

Mehr von Unity Technologies Japan K.K. (20)

建築革命、更に更に進化!便利さ向上【Unity Reflect ver 3.0 】
建築革命、更に更に進化!便利さ向上【Unity Reflect ver 3.0 】建築革命、更に更に進化!便利さ向上【Unity Reflect ver 3.0 】
建築革命、更に更に進化!便利さ向上【Unity Reflect ver 3.0 】
 
UnityのクラッシュをBacktraceでデバッグしよう!
UnityのクラッシュをBacktraceでデバッグしよう!UnityのクラッシュをBacktraceでデバッグしよう!
UnityのクラッシュをBacktraceでデバッグしよう!
 
Unityで始めるバーチャルプロダクション
Unityで始めるバーチャルプロダクションUnityで始めるバーチャルプロダクション
Unityで始めるバーチャルプロダクション
 
ビジュアルスクリプティング (旧:Bolt) で始めるUnity入門3日目 ゲームをカスタマイズしよう
ビジュアルスクリプティング (旧:Bolt) で始めるUnity入門3日目 ゲームをカスタマイズしようビジュアルスクリプティング (旧:Bolt) で始めるUnity入門3日目 ゲームをカスタマイズしよう
ビジュアルスクリプティング (旧:Bolt) で始めるUnity入門3日目 ゲームをカスタマイズしよう
 
ビジュアルスクリプティングで始めるUnity入門2日目 ゴールとスコアの仕組み - Unityステーション
ビジュアルスクリプティングで始めるUnity入門2日目 ゴールとスコアの仕組み - Unityステーションビジュアルスクリプティングで始めるUnity入門2日目 ゴールとスコアの仕組み - Unityステーション
ビジュアルスクリプティングで始めるUnity入門2日目 ゴールとスコアの仕組み - Unityステーション
 
ビジュアルスクリプティングで始めるUnity入門1日目 プレイヤーを動かそう
ビジュアルスクリプティングで始めるUnity入門1日目 プレイヤーを動かそうビジュアルスクリプティングで始めるUnity入門1日目 プレイヤーを動かそう
ビジュアルスクリプティングで始めるUnity入門1日目 プレイヤーを動かそう
 
PlasticSCMの活用テクニックをハンズオンで一緒に学ぼう!
PlasticSCMの活用テクニックをハンズオンで一緒に学ぼう!PlasticSCMの活用テクニックをハンズオンで一緒に学ぼう!
PlasticSCMの活用テクニックをハンズオンで一緒に学ぼう!
 
点群を使いこなせ! 可視化なんて当たり前、xRと点群を組み合わせたUnityの世界 【Interact , Stipple】
点群を使いこなせ! 可視化なんて当たり前、xRと点群を組み合わせたUnityの世界 【Interact , Stipple】点群を使いこなせ! 可視化なんて当たり前、xRと点群を組み合わせたUnityの世界 【Interact , Stipple】
点群を使いこなせ! 可視化なんて当たり前、xRと点群を組み合わせたUnityの世界 【Interact , Stipple】
 
Unity教える先生方注目!ティーチャートレーニングデイを体験しよう
Unity教える先生方注目!ティーチャートレーニングデイを体験しようUnity教える先生方注目!ティーチャートレーニングデイを体験しよう
Unity教える先生方注目!ティーチャートレーニングデイを体験しよう
 
「原神」におけるコンソールプラットフォーム開発
「原神」におけるコンソールプラットフォーム開発「原神」におけるコンソールプラットフォーム開発
「原神」におけるコンソールプラットフォーム開発
 
FANTASIANの明日使えない特殊テクニック教えます
FANTASIANの明日使えない特殊テクニック教えますFANTASIANの明日使えない特殊テクニック教えます
FANTASIANの明日使えない特殊テクニック教えます
 
インディーゲーム開発の現状と未来 2021
インディーゲーム開発の現状と未来 2021インディーゲーム開発の現状と未来 2021
インディーゲーム開発の現状と未来 2021
 
建築革命、更に進化!デジタルツイン基盤の真打ち登場【概要編 Unity Reflect ver 2.1 】
建築革命、更に進化!デジタルツイン基盤の真打ち登場【概要編 Unity Reflect ver 2.1 】建築革命、更に進化!デジタルツイン基盤の真打ち登場【概要編 Unity Reflect ver 2.1 】
建築革命、更に進化!デジタルツイン基盤の真打ち登場【概要編 Unity Reflect ver 2.1 】
 
Burstを使ってSHA-256のハッシュ計算を高速に行う話
Burstを使ってSHA-256のハッシュ計算を高速に行う話Burstを使ってSHA-256のハッシュ計算を高速に行う話
Burstを使ってSHA-256のハッシュ計算を高速に行う話
 
Cinemachineで見下ろし視点のカメラを作る
Cinemachineで見下ろし視点のカメラを作るCinemachineで見下ろし視点のカメラを作る
Cinemachineで見下ろし視点のカメラを作る
 
徹底解説 Unity Reflect【開発編 ver2.0】
徹底解説 Unity Reflect【開発編 ver2.0】徹底解説 Unity Reflect【開発編 ver2.0】
徹底解説 Unity Reflect【開発編 ver2.0】
 
徹底解説 Unity Reflect【概要編 ver2.0】
徹底解説 Unity Reflect【概要編 ver2.0】徹底解説 Unity Reflect【概要編 ver2.0】
徹底解説 Unity Reflect【概要編 ver2.0】
 
Unityティーチャートレーニングデイ -認定プログラマー編-
Unityティーチャートレーニングデイ -認定プログラマー編-Unityティーチャートレーニングデイ -認定プログラマー編-
Unityティーチャートレーニングデイ -認定プログラマー編-
 
Unityティーチャートレーニングデイ -認定3Dアーティスト編-
Unityティーチャートレーニングデイ -認定3Dアーティスト編-Unityティーチャートレーニングデイ -認定3Dアーティスト編-
Unityティーチャートレーニングデイ -認定3Dアーティスト編-
 
Unityティーチャートレーニングデイ -認定アソシエイト編-
Unityティーチャートレーニングデイ -認定アソシエイト編-Unityティーチャートレーニングデイ -認定アソシエイト編-
Unityティーチャートレーニングデイ -認定アソシエイト編-
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Kürzlich hochgeladen (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

【Unity】Scriptable object 入門と活用例

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61. [CreateAssetMenu]
 public class TankConfig : ScriptableObject
 {
 public float speed;
 public float rotate;
 }

  • 62. public class TankController : MonoBehaviour
 {
 [SerializeField] TankConfig config;
 
 public void Update ()
 {
 var v = Input.GetAxis ("Vertical1");
 var x = Input.GetAxis ("Horizontal1");
 if (v != 0)
 GetComponent<NavMeshAgent> ().Move (transform.forward * (v * config.speed));
 if (x != 0)
 transform.localRotation *= Quaternion.AngleAxis (x * config.rotate, Vector3.up);
 }
 }

  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73. public class TankController : MonoBehaviour
 {
 [SerializeField] TankAIBase ai;
 
 public void Update ()
 {
 ai.Do(gameObject);
 }
 } public abstract class TankAIBase : ScriptableObject
 {
 public virtual void Do (GameObject obj) { }
 }
  • 74. [CreateAssetMenu]
 public class TanksStand : TankAIBase{}
 [CreateAssetMenu]
 public class TankRotate : TankAIBase
 {
 public float rotate = 2;
 
 public override void Do (GameObject obj)
 {
 obj.transform.localRotation *= Quaternion.AngleAxis (rotate, Vector3.up);
 }
 }

  • 75. [CreateAssetMenu]
 public class TankMove : TankAIBase
 {
 public float speed = 0.5f;
 
 public override void Do (GameObject obj)
 {
 obj.GetComponent<NavMeshAgent>().Move(obj.transform.forward * speed);
 }
 }
  • 76.
  • 77.
  • 78.
  • 79.
  • 80. public class TankController : MonoBehaviour
 {
 public void Move(float accel)
 {
 GetComponent<NavMeshAgent>().Move(transform.forward * (accel * 0.2f));
 }
 } [CreateAssetMenu]
 public class TankData : ScriptableObject
 {
 public TankController tankController{get; set;}
 
 public void Up () { tankController.Move(5); }
 public void Down () { tankController.Move(-5); }
 }

  • 81. [DefaultExecutionOrder (-100)]
 public class EventTriggerBehaviour : MonoBehaviour
 {
 [SerializeField]
 UnityEvent onAwake = new UnityEvent (), onDestroy = new UnityEvent ();
 
 void Awake ()
 {
 onAwake.Invoke ();
 }
 
 void OnDestroy ()
 {
 onDestroy.Invoke ();
 }
 }

  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93. [CreateAssetMenu]
 public class Config : ScriptableObject
 {
 public Item[] items = new Item[0];
 
 [System.Serializable]
 public class Item
 {
 public Texture texture;
 public int param;
 public string name;
 }
 } [CustomEditor (typeof(Config))]
 public class ConfigEditor : Editor
 {
 public override void OnInspectorGUI ()
 {
 base.OnInspectorGUI();
 var config = (Config)target; // レイアウト記述 } }
  • 94. [CreateAssetMenu]
 public class Config : ScriptableObject
 {
 public Item[] items = new Item[0];
 
 [System.Serializable]
 public class Item
 {
 [PreviewTexture]
 public Texture texture;
 [Range(0, 100)]
 public int param;
 public string name;
 }
 }
  • 95. [CreateAssetMenu]
 public class Data : ScriptableObject
 {
 [SerializeField] int count;
 
 void OnValidate ()
 {
 count = Mathf.Clamp (count, 0, 99);
 }
 }
  • 96.
  • 97.
  • 98.
  • 100. public class param1_importer : AssetPostprocessor { 
 static void OnPostprocessAllAssets ( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { ExcelItem data = (ExcelItem)AssetDatabase.LoadAssetAtPath (exportPath, typeof(ExcelItem));
 if (data == null) {
 data = ScriptableObject.CreateInstance<ExcelItem> ();
 AssetDatabase.CreateAsset ((ScriptableObject)data, exportPath);
 } // インポート処理 ScriptableObject obj = AssetDatabase.LoadAssetAtPath ( exportPath, typeof(ScriptableObject)) as ScriptableObject; EditorUtility.SetDirty (obj); } }
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110. [CreateAssetMenu]
 public class SampleDictionary : ScriptableObject, ISerializationCallbackReceiver
 {
 const string path = "item.json";
 
 public Item item = new Item ();
 
 public void OnBeforeSerialize ()
 {
 var json = JsonUtility.ToJson (item);
 File.WriteAllText (path, json);
 }
 
 public void OnAfterDeserialize ()
 {
 if (File.Exists (path)) {
 var json = File.ReadAllText (path); 
 JsonUtility.FromJsonOverwrite (json, item);
 }
 }
 } 

  • 111.
  • 112.
  • 113. public abstract class ResettableScriptableObject : ScriptableObject
 {
 public abstract void Reset ();
 }
 [CreateAssetMenu]
 public class SaveData : ResettableScriptableObject
 { public int count = 0; 
 public override void Reset ()
 { //初期化コード count = 0; } }

  • 114. public class DataResetter : MonoBehaviour
 {
 public ResettableScriptableObject[] resettableScriptableObjects;
 
 private void Awake ()
 {
 for (int i = 0; i < resettableScriptableObjects.Length; i++)
 {
 resettableScriptableObjects[i].Reset ();
 }
 }
 }

  • 115. public abstract class ResettableScriptableObject : ScriptableObject
 {
 [SerializeField] int _count = 0;
 public int count{get; set;}
 
 void OnEnable()
 {
 count = _count;
 }
 }

  • 116. public class ResettableScriptableObject : ScriptableObject 
 {
 protected virtual void OnEnable()
 {
 #if UNITY_EDITOR
 if( EditorApplication.isPlayingOrWillChangePlaymode == true ){
 UnityEditor.EditorApplication.playModeStateChanged += (state) => {
 if( EditorApplication.isPlayingOrWillChangePlaymode == false) {
 Resources.UnloadAsset(this);
 }
 } ;
 }
 #endif
 }
 }

  • 117. [CreateAssetMenu]
 public class Config : ResettableScriptableObject
 {
 public float _count;
 }

  • 119.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.