public void LoadScriptableObject()
    {
        string             path = "Assets/Z_Other/ScriptableObject/MySO2.asset";
        MyScriptableObject ins  = AssetDatabase.LoadAssetAtPath <MyScriptableObject>(path);

        Debug.LogFormat("--- LoadAsset success, {0}, {1}, {2}, {3}", ins.myname, ins.age, ins.raduis, ins.texList.Count);
    }
 //
 void OnGUI()
 {
     //非Editor模式下使用..
     if (GUILayout.Button("Loading.."))
     {
         MyScriptableObject holder = (MyScriptableObject)Resources.Load("dataHolder", typeof(MyScriptableObject));
     }
 }
    static void DoIt()
    {
        MyScriptableObject asset = ScriptableObject.CreateInstance <MyScriptableObject>();

        AssetDatabase.CreateAsset(asset, "Assets/MyScriptableObject.asset");
        AssetDatabase.SaveAssets();

        EditorUtility.FocusProjectWindow();
        Selection.activeObject = asset;
    }
示例#4
0
        private static void SelectBase()
        {
            var presetBase = MyScriptableObject.LoadAssetsFromResources <AssetsPresetPreprocessBase>().FirstOrDefault();

            if (presetBase == null)
            {
                presetBase = MyScriptableObject.CreateAssetWithFolderDialog <AssetsPresetPreprocessBase>("AssetsPresetPostprocessBase");
            }

            if (presetBase != null)
            {
                Selection.activeObject = presetBase;
            }
        }
		void OnEnable() {
			if(m == null) {
				string path = "Assets/Editor/Test3-SavedScriptableObject/SaveData.asset";
				m = AssetDatabase.LoadAssetAtPath<MyScriptableObject>(path);
				if(m == null) {
					m = CreateInstance<MyScriptableObject>();
					AssetDatabase.CreateAsset(m, path);
					AssetDatabase.SaveAssets();
					AssetDatabase.Refresh();
				}
			}

			titleContent.text = WINDOW_TITLE;
		}
示例#6
0
        private static void AssertComponentsInScene()
        {
                        #if UNITY_2020_1_OR_NEWER
            var behaviours = Object.FindObjectsOfType <MonoBehaviour>(true);
                        #else
            var behaviours = Object.FindObjectsOfType <MonoBehaviour>();
                        #endif
            // ReSharper disable once CoVariantArrayConversion
            AssertComponents(behaviours);

            if (MyBoxSettings.EnableSOCheck)
            {
                var scriptableObjects = MyScriptableObject.LoadAssets <ScriptableObject>();
                // ReSharper disable once CoVariantArrayConversion
                AssertComponents(scriptableObjects);
            }
        }
    static void CreateDataAsset()
    {
        //資料 Asset 路徑
        string holderAssetPath = "Assets/Resources/";

        if (!Directory.Exists(holderAssetPath))
        {
            Directory.CreateDirectory(holderAssetPath);
        }

        //建立實體
        MyScriptableObject holder = ScriptableObject.CreateInstance <MyScriptableObject> ();

        //使用 holder 建立名為 dataHolder.asset 的資源
        AssetDatabase.CreateAsset(holder, holderAssetPath + "dataHolder.asset");
        //
        EditorUtility.DisplayDialog("create Asset", "dataHolder.asset", "OK", "");
    }
示例#8
0
        private bool PreloadBase()
        {
            if (_preprocessBaseChecked)
            {
                return(_preprocessBase != null);
            }
            if (_preprocessBase == null)
            {
                _preprocessBase = MyScriptableObject.LoadAssetsFromResources <AssetsPresetPreprocessBase>().FirstOrDefault();
                if (_preprocessBase == null)
                {
                    _preprocessBase = MyScriptableObject.LoadAssets <AssetsPresetPreprocessBase>().SingleOrDefault();
                }

                _preprocessBaseChecked = true;
            }

            return(_preprocessBase != null);
        }
    public void CreateScriptableObject()
    {
        MyScriptableObject ins = ScriptableObject.CreateInstance <MyScriptableObject>();

        ins.myname = "hello";
        ins.age    = 111;
        ins.raduis = 4.2f;
        string path = "Assets/Z_Other/ScriptableObject/MySO2.asset";

        string  texpath1 = "Assets/Common/tex/build_sh_jb.png";
        string  texpath2 = "Assets/Common/tex/Plasma_1.png";
        Texture tex1     = AssetDatabase.LoadAssetAtPath <Texture>(texpath1);
        Texture tex2     = AssetDatabase.LoadAssetAtPath <Texture>(texpath2);

        ins.texList.Add(tex1);
        ins.texList.Add(tex2);

        AssetDatabase.CreateAsset(ins, path);
        Debug.LogFormat("--- CreateAsset success, path:{0}", path);
    }
 public void DoSomething(GameObject go)
 {
     var behaviour        = new MyMonoBehaviour();
     var scriptableObject = new MyScriptableObject();
 }
 public static void DoSomething()
 {
     var so = new MyScriptableObject();
 }
		void OnEnable() {
			if(m == null) 
				m = CreateInstance<MyScriptableObject>();

			titleContent.text = WINDOW_TITLE;
		}