Пример #1
0
        private bool HaveStats()
        {
            GameObject activeObj = Selection.activeObject as GameObject;

            if (activeObj == null)
            {
                stats = null;
                return(false);
            }

            prefabRoot = PrefabUtility.GetOutermostPrefabInstanceRoot(activeObj);

            warnPrefab = prefabRoot != null;

            StatsCog newStats = activeObj.GetComponent <StatsCog>();

            if (stats != newStats || (stats == null && newStats != null))
            {
                stats = newStats;
                if (stats == null)
                {
                    statsEditor      = null;
                    lastEffects      = null;
                    effectListEditor = null;
                    return(false);
                }
                else
                {
                    statsEditor = (StatsCogEditor)Editor.CreateEditor(stats, typeof(StatsCogEditor));
                    return(true);
                }
            }

            return(stats != null);
        }
Пример #2
0
        internal void DrawEffectsList()
        {
            SimpleProperty("effectList");
            if (myTarget.effectList == null)
            {
                if (GUILayout.Button("Create New Effect List"))
                {
                    if (string.IsNullOrWhiteSpace(myTarget.effectFolder))
                    {
                        myTarget.effectFolder = Application.dataPath;
                    }
                    string path = EditorUtility.SaveFilePanelInProject("Save Category", "New Effect List", "asset", "Select a location to save the Effect List", myTarget.effectFolder);
                    if (path.Length != 0)
                    {
                        myTarget.effectFolder = System.IO.Path.GetDirectoryName(path);

                        StatEffectList effectList = (StatEffectList)ScriptableObject.CreateInstance(typeof(StatEffectList));
                        effectList.name = System.IO.Path.GetFileNameWithoutExtension(path);
                        AssetDatabase.CreateAsset(effectList, path);
                        AssetDatabase.SaveAssets();

                        myTarget.effectList = effectList;
                    }
                }
            }
        }
Пример #3
0
        private void DrawEffects()
        {
            GUILayout.BeginHorizontal(GUILayout.MaxWidth(750));

            GUILayout.BeginVertical(GUILayout.Width(300));
            effectsPos = GUILayout.BeginScrollView(effectsPos);
            statsEditor.DrawEffectsList();

            if (stats.effectList != lastEffects)
            {
                lastEffects = stats.effectList;
                if (lastEffects != null)
                {
                    effectListEditor = (StatEffectListEditor)Editor.CreateEditor(stats.effectList, typeof(StatEffectListEditor));
                }
            }

            if (effectListEditor == null)
            {
                return;
            }

            int editId = effectListEditor.DrawEffectList();

            if (editId > -1)
            {
                editEffect   = lastEffects.availableEffects[editId];
                effectEditor = (StatEffectEditor)Editor.CreateEditor(editEffect);
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            GUILayout.Space(32);

            GUILayout.BeginVertical(GUILayout.Width(300));
            if (editEffect == null)
            {
                if (addEffect == null)
                {
                    addEffect      = (StatEffect)ScriptableObject.CreateInstance(typeof(StatEffect));
                    addEffect.name = "New Effect";
                    effectEditor   = (StatEffectEditor)Editor.CreateEditor(addEffect);
                }

                effectEditor.serializedObject.Update();
                SectionHeader("Create Effect");
                effectPos = GUILayout.BeginScrollView(effectPos);
                effectEditor.DrawInspector();
                GUILayout.EndScrollView();

                GUILayout.Space(16);
                if (GUILayout.Button("Create and Add"))
                {
                    if (string.IsNullOrWhiteSpace(stats.effectFolder))
                    {
                        stats.effectFolder = Application.dataPath;
                    }
                    string path = EditorUtility.SaveFilePanelInProject("Save Effect", addEffect.displayName, "asset", "Select a location to save the effect", stats.effectFolder);
                    if (path.Length != 0)
                    {
                        effectListEditor.serializedObject.Update();
                        stats.effectFolder = System.IO.Path.GetDirectoryName(path);

                        addEffect.name = System.IO.Path.GetFileNameWithoutExtension(path);
                        AssetDatabase.CreateAsset(addEffect, path);
                        AssetDatabase.SaveAssets();

                        effectListEditor.AddEffect(AssetDatabase.LoadAssetAtPath(path, typeof(StatEffect)) as StatEffect);
                        addEffect = null;
                        effectPos = Vector2.zero;
                        GUI.FocusControl("Clear");
                        effectListEditor.serializedObject.ApplyModifiedProperties();
                    }
                }

                effectEditor.serializedObject.ApplyModifiedProperties();
            }
            else
            {
                effectEditor.serializedObject.Update();
                SectionHeader("Edit Effect");
                effectPos = GUILayout.BeginScrollView(effectPos);
                effectEditor.DrawInspector();
                GUILayout.EndScrollView();

                GUILayout.Space(16);
                if (GUILayout.Button("Done"))
                {
                    addEffect  = null;
                    editEffect = null;
                    GUI.FocusControl("Clear");
                    Repaint();
                }
                else
                {
                    effectEditor.serializedObject.ApplyModifiedProperties();
                }
            }
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }