Exemplo n.º 1
0
        public ConstellationScriptInfos Draw(ConstellationScriptInfos[] scriptsInfos)
        {
            GUI.color = Color.white;
            GUILayout.BeginHorizontal();

            foreach (var scriptInfos in scriptsInfos)
            {
                var constellationPath = scriptInfos.ScriptPath.Split('/');
                var name = constellationPath[constellationPath.Length - 1].Split('.')[0];
                if (scriptInfos.IsIstance == true)
                {
                    GUI.color         = Color.yellow;
                    constellationPath = scriptInfos.InstancePath.Split('/');
                    name = constellationPath[constellationPath.Length - 1].Split('.')[0];
                }

                if (GUILayout.Button(name, "MiniToolbarButton", GUILayout.MaxWidth(125), GUILayout.MinWidth(125)))
                {
                    return(scriptInfos);
                }

                if (GUILayout.Button("X", "MiniToolbarButton", GUILayout.MaxWidth(20), GUILayout.MinWidth(20)))
                {
                    removeNode = scriptInfos;
                }
                GUI.color = Color.grey;
                GUILayout.Space(10);
            }
            GUI.color = Color.white;
            GUILayout.EndHorizontal();
            return(null);
        }
Exemplo n.º 2
0
        public ConstellationScriptInfos ConstellationToRemove()
        {
            var nodeToRemove = removeNode;

            removeNode = null;
            return(nodeToRemove);
        }
Exemplo n.º 3
0
        public void SaveInstance(ConstellationScriptInfos scriptInfos)
        {
            var newScript = ScriptableObject.CreateInstance <ConstellationBehaviourScript>();
            var path      = "";

            if (scriptInfos.IsIstance)
            {
                path = scriptInfos.ScriptPath;
            }
            else
            {
                return;
            }
            if (path == "")
            {
                path = EditorUtility.SaveFilePanel("Save Constellation", Application.dataPath, "NewConstellation" + ".asset", "asset");
                if (path.Length == 0)
                {
                    return;
                }

                if (path.StartsWith(Application.dataPath))
                {
                    path = "Assets" + path.Substring(Application.dataPath.Length);
                }
            }
            newScript.script = Script.script;
            AssetDatabase.CreateAsset(newScript, path);
            SaveAll();
            RefreshConstellationEditorDataList();
        }
Exemplo n.º 4
0
 public bool CloseOpenedConstellation(ConstellationScriptInfos scriptInfos)
 {
     if (scriptInfos == null)
     {
         return(false);
     }
     EditorData.LastOpenedConstellationPath.Remove(scriptInfos);
     OpenedScripts.Remove(scriptInfos);
     //Script = null;
     return(true);
 }
Exemplo n.º 5
0
        public ConstellationScript Recover(ConstellationScriptInfos _scriptInfos)
        {
            ConstellationScript t = (ConstellationScript)AssetDatabase.LoadAssetAtPath(_scriptInfos.ScriptPath, typeof(ConstellationScript));

            Script = t;
            if (t != null)
            {
                OpenedScripts = new List <ConstellationScriptInfos>(EditorData.LastOpenedConstellationPath);
                OpenedScripts.Remove(_scriptInfos);
                OpenedScripts.Insert(0, _scriptInfos);
                return(t);
            }
            else
            {
                throw new ScriptNotFoundAtPath(_scriptInfos.ScriptPath);
            }
        }
Exemplo n.º 6
0
        public void OpenConstellationInstance <T> (Constellation.Constellation constellation, string instanceSourcePath) where T : ConstellationScript
        {
            var constellationScript = ScriptableObject.CreateInstance <T>();

            constellationScript.IsInstance    = true;
            constellationScript.CanChangeType = false;
            var path = "Assets/Constellation/Editor/EditorData/Temp/" + constellation.Name + "(Instance).asset";

            Script = constellationScript;
            AssetDatabase.CreateAsset(constellationScript, path);

            var nodes = constellation.GetNodes();
            var links = constellation.GetLinks();

            var newInstanceObject = new ConstellationScriptInfos(instanceSourcePath, ConstellationScriptInfos.ConstellationScriptTag.NoTag, true, path);

            OpenedScripts = new List <ConstellationScriptInfos>(EditorData.LastOpenedConstellationPath);
            if (!OpenedScripts.Contains(newInstanceObject))
            {
                OpenedScripts.Insert(0, newInstanceObject);
            }
            else
            {
                OpenedScripts.Remove(newInstanceObject);
                OpenedScripts.Insert(0, newInstanceObject);
            }

            foreach (var node in nodes)
            {
                Script.AddNode(node);
            }

            foreach (var link in links)
            {
                Script.AddLink(link);
            }

            SaveEditorData();
        }
Exemplo n.º 7
0
        public ConstellationScript OpenConstellation(ConstellationScriptInfos _path = null, bool save = true)
        {
            ConstellationScriptInfos newScriptInfos;

            if (_path == null)
            {
                newScriptInfos = new ConstellationScriptInfos(EditorUtility.OpenFilePanel("Load constellation", Application.dataPath, "asset"),
                                                              ConstellationScriptInfos.ConstellationScriptTag.NoTag,
                                                              false);
                if (newScriptInfos.ScriptPath.Length == 0)
                {
                    return(null);
                }
            }
            else
            {
                newScriptInfos = _path;
            }

            if (newScriptInfos.ScriptPath.StartsWith(Application.dataPath))
            {
                newScriptInfos.ScriptPath = "Assets" + newScriptInfos.ScriptPath.Substring(Application.dataPath.Length);
            }
            ConstellationScript t = (ConstellationScript)AssetDatabase.LoadAssetAtPath(newScriptInfos.ScriptPath, typeof(ConstellationScript));

            Script = t;
            if (Script == null)
            {
                throw new ScriptNotFoundAtPath(_path.ScriptPath);
            }

            OpenedScripts = new List <ConstellationScriptInfos>(EditorData.LastOpenedConstellationPath);
            var isAlreadyOpened = false;
            var openedIndex     = 0;

            foreach (var openedScripts in OpenedScripts)
            {
                if (openedScripts.ScriptPath == newScriptInfos.ScriptPath)
                {
                    isAlreadyOpened = true;
                    break;
                }
                openedIndex++;
            }
            //Debug.Log(openedIndex);
            if (!isAlreadyOpened)
            {
                OpenedScripts.Insert(0, newScriptInfos);
            }
            else
            {
                OpenedScripts.Remove(OpenedScripts[openedIndex]);
                OpenedScripts.Insert(0, newScriptInfos);
            }

            var name = Path.GetFileNameWithoutExtension(newScriptInfos.ScriptPath.Split('/').Last());

            Script.script.Name = name;

            if (save)
            {
                SaveEditorData();
            }

            return(t);
        }