コード例 #1
0
    public void OnEnable()
    {
        if (root == null)
        {
            if (AssetDatabase.GetAssetPath(gameObject).Length == 0)
            {
                loadPrefab = GetInstanceID();
                root       = ScriptableObject.CreateInstance <CGRoot>();
            }
            else
            {
                CreateGUI source = null;

                foreach (CreateGUI cg in (CreateGUI[])Object.FindObjectsOfType(typeof(CreateGUI)))
                {
                    if (cg.GetInstanceID() == loadPrefab)
                    {
                        source = cg;
                        break;
                    }
                }

                if (source == null)
                {
                    root = ScriptableObject.CreateInstance <CGRoot>();
                }
                else
                {
                    root = (CGRoot)Instantiate(source.root);
                }

                string path = AssetDatabase.GetAssetPath(gameObject);
                path = path.TrimEnd(".prefab".ToCharArray());
                string[] splitpath = path.Split('/');
                path = path.TrimEnd(splitpath[splitpath.Length - 1].ToCharArray());
                AssetDatabase.CreateFolder(path.TrimEnd('/'), name + "_CG");

                try{
                    path = path + name + "_CG/" + splitpath[splitpath.Length - 1] + "_CG.asset";
                    AssetDatabase.CreateAsset(root, path);
                    root.SetChildren(SaveRecursively(root.GetChildren(), path));
                }catch (System.Exception e) { Debug.LogWarning("Create GUI could not create CreateGUI File (" + e.Message + ")"); }
            }
        }

        if (AssetDatabase.GetAssetPath(gameObject).Length == 0)
        {
            root = (CGRoot)Instantiate(root);
            try{
                root.SetChildren(SaveRecursively(root.GetChildren(), ""));
            }catch (System.Exception) {}
            loadPrefab = GetInstanceID();
        }
    }
コード例 #2
0
ファイル: CreateGUI.cs プロジェクト: Zewzit/OZone-GameRealm
    public void OnEnable()
    {
        if(root == null){

            if(AssetDatabase.GetAssetPath(gameObject).Length == 0){

                loadPrefab = GetInstanceID();
                root = ScriptableObject.CreateInstance<CGRoot>();

            }else{

                CreateGUI source = null;

                foreach(CreateGUI cg in (CreateGUI[]) Object.FindObjectsOfType(typeof(CreateGUI))){

                    if(cg.GetInstanceID() == loadPrefab){

                        source = cg;
                        break;
                    }
                }

                if(source == null) root = ScriptableObject.CreateInstance<CGRoot>();
                else root = (CGRoot) Instantiate(source.root);

                string path = AssetDatabase.GetAssetPath(gameObject);
                path = path.TrimEnd(".prefab".ToCharArray());
                string[] splitpath = path.Split('/');
                path = path.TrimEnd(splitpath[splitpath.Length-1].ToCharArray());
                AssetDatabase.CreateFolder(path.TrimEnd('/'),name+"_CG");

                try{
                    path = path+name+"_CG/"+splitpath[splitpath.Length-1]+"_CG.asset";
                    AssetDatabase.CreateAsset(root,path);
                    root.SetChildren(SaveRecursively(root.GetChildren(),path));
                }catch(System.Exception e){Debug.LogWarning("Create GUI could not create CreateGUI File ("+e.Message+")");}
            }
        }

        if(AssetDatabase.GetAssetPath(gameObject).Length == 0){

            root = (CGRoot) Instantiate(root);
            try{
                root.SetChildren(SaveRecursively(root.GetChildren(),""));
            }catch(System.Exception){}
            loadPrefab = GetInstanceID();
        }
    }