Beispiel #1
0
    public override void OnInspectorGUI()
    {
        _ProFlareAtlas = target as ProFlareAtlas;
        CheckUndo();
        //	 base.OnInspectorGUI();
        FlareEditorHelper.DrawGuiDivider();
        GUIStyle title        = FlareEditorHelper.TitleStyle();
        GUIStyle thinButton   = FlareEditorHelper.ThinButtonStyle();
        GUIStyle enumDropDown = FlareEditorHelper.EnumStyleButton();
        GUIStyle redButton    = FlareEditorHelper.ThinButtonRedStyle();


        EditorGUILayout.LabelField("ProFlare Atlas Editor", title);
        GUILayout.Space(10f);

        _ProFlareAtlas.texture = EditorGUILayout.ObjectField("Flare Atlas Texture", _ProFlareAtlas.texture, typeof(Texture2D), false) as Texture2D;

        if (_ProFlareAtlas.texture == null)
        {
            EditorGUILayout.HelpBox("Assign a texture to the atlas.", MessageType.Warning, true);
            return;
        }
        TextAsset ta = EditorGUILayout.ObjectField("Atlas JSON Import", null, typeof(TextAsset), false) as TextAsset;

        if (ta != null)
        {
            FlareJson.LoadSpriteData(_ProFlareAtlas, ta);
            Updated = true;
        }

        FlareEditorHelper.DrawGuiDivider();
        EditorGUILayout.LabelField("Atlas Elements", title);
        GUILayout.Space(6f);

        EditorGUILayout.BeginHorizontal();


        if (_ProFlareAtlas.elementsList.Count < 1)
        {
            EditorGUILayout.HelpBox("No Elements in flare atlas", MessageType.Warning, true);
        }
        else
        {
            _ProFlareAtlas.elementNameList = new string[_ProFlareAtlas.elementsList.Count];

            for (int i = 0; i < _ProFlareAtlas.elementNameList.Length; i++)
            {
                _ProFlareAtlas.elementNameList[i] = _ProFlareAtlas.elementsList[i].name;
            }


            int _ProFlareAtlasElementNumber = EditorGUILayout.Popup(_ProFlareAtlas.elementNumber, _ProFlareAtlas.elementNameList, enumDropDown);

            if (_ProFlareAtlasElementNumber != _ProFlareAtlas.elementNumber)
            {
                _ProFlareAtlas.elementNumber = _ProFlareAtlasElementNumber;
                renameString = _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].name;
            }

            if (GUILayout.Button("EDIT", thinButton))
            {
                Updated = true;
                if (_ProFlareAtlas.editElements)
                {
                    _ProFlareAtlas.editElements = false;
                }
                else
                {
                    _ProFlareAtlas.editElements = true;
                }
            }
        }

        if (GUILayout.Button("ADD NEW", thinButton))
        {
            _ProFlareAtlas.editElements = true;

            ProFlareAtlas.Element element = new ProFlareAtlas.Element();

            element.name = "New Element " + _ProFlareAtlas.elementsList.Count;

            renameString     = element.name;
            element.Imported = false;

            _ProFlareAtlas.elementsList.Add(element);

            _ProFlareAtlas.elementNumber = _ProFlareAtlas.elementsList.Count - 1;


            Updated = true;
        }

        EditorGUILayout.EndHorizontal();

        if (_ProFlareAtlas.elementsList.Count < 1)
        {
            return;
        }

        EditorGUILayout.BeginVertical("box");
        GUILayout.Space(20f);

        Rect lastRect = GUILayoutUtility.GetLastRect();

        Rect outerRect2 = new Rect(lastRect.center.x, 0 + lastRect.yMin, 200, 200);

        if (_ProFlareAtlas.elementsList.Count > 0)
        {
            GUI.DrawTextureWithTexCoords(outerRect2, _ProFlareAtlas.texture, _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV, false);
            GUILayout.Space(200f);
        }
        GUI.enabled = _ProFlareAtlas.editElements;



        if (_ProFlareAtlas.editElements)
        {
            int extra = 0;
#if UNITY_4_3
            extra = 10;
#endif
            Rect outerRect3 = new Rect(107 + extra, lastRect.yMin, 0.5f, 200);

            Rect rect = new Rect(0, 0, 1, 1);

            GUI.DrawTextureWithTexCoords(outerRect3, EditorGUIUtility.whiteTexture, rect, false);

            Rect outerRect4 = new Rect(7 + extra, 100 + lastRect.yMin, 200, 0.5f);

            GUI.DrawTextureWithTexCoords(outerRect4, EditorGUIUtility.whiteTexture, rect, true);
        }

        GUILayout.BeginHorizontal();

        if (!_ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].Imported)
        {
            renameString = EditorGUILayout.TextField("Name", renameString);
            if (GUILayout.Button("RENAME"))
            {
                Updated = true;
                _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].name = renameString;
            }
        }
        else
        {
            EditorGUILayout.LabelField("Name - " + renameString);
        }

        GUILayout.EndHorizontal();

        EditorGUILayout.Toggle("Imported :", _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].Imported);

        float width  = EditorGUILayout.Slider("Width", _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.width, 0f, 1f);
        float height = EditorGUILayout.Slider("Height", _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.height, 0f, 1f);

        float CenterX = EditorGUILayout.Slider("Center X", _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.center.x, 0f, 1f);
        float CenterY = EditorGUILayout.Slider("Center Y", _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.center.y, 0f, 1f);

        float xMin = _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.xMin;
        float yMin = _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV.yMin;

        Rect newRect = new Rect(xMin, yMin, width, height);

        newRect.center = new Vector2(CenterX, CenterY);

        GUILayout.Space(40f);

        _ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber].UV = newRect;

        if (GUILayout.Button("DELETE ELEMENT", redButton))
        {
            Updated = true;
            _ProFlareAtlas.elementsList.Remove(_ProFlareAtlas.elementsList[_ProFlareAtlas.elementNumber]);
            _ProFlareAtlas.elementNumber = 0;
        }

        EditorGUILayout.EndVertical();

        GUI.enabled = true;


        if (GUI.changed || Updated)
        {
            Updated    = false;
            guiChanged = true;
            EditorUtility.SetDirty(target);
        }

        FlareEditorHelper.DrawGuiDivider();
    }
Beispiel #2
0
    public override void OnInspectorGUI()
    {
        GUIStyle title = FlareEditorHelper.TitleStyle();

        FlareEditorHelper.DrawGuiDivider();

        EditorGUILayout.LabelField("Pro Flare Batch :", title);

        GUILayout.Space(10f);

        _ProFlareBatch = target as ProFlareBatch;
        //base.DrawDefaultInspector();
        _ProFlareBatch.debugMessages = EditorGUILayout.Toggle("Debug Messages", _ProFlareBatch.debugMessages);

        EditorGUILayout.BeginHorizontal();

        EditorGUILayout.LabelField("Mode", GUILayout.MaxWidth(100));

        ProFlareBatch.Mode _mode = (ProFlareBatch.Mode)EditorGUILayout.EnumPopup(_ProFlareBatch.mode);

        if (_mode != _ProFlareBatch.mode)
        {
            _ProFlareBatch.mode = _mode;

            switch (_mode)
            {
            case (ProFlareBatch.Mode.Standard): {
                _ProFlareBatch.SingleCamera_Mode = false;
                _ProFlareBatch.VR_Mode           = false;
            } break;

            case (ProFlareBatch.Mode.SingleCamera): {
                _ProFlareBatch.SingleCamera_Mode = true;
                _ProFlareBatch.VR_Mode           = false;
            } break;

            case (ProFlareBatch.Mode.VR): {
                _ProFlareBatch.SingleCamera_Mode = false;
                _ProFlareBatch.VR_Mode           = true;
            } break;
            }

            Updated = true;
        }


        EditorGUILayout.EndHorizontal();

        ProFlareAtlas _atlas = EditorGUILayout.ObjectField("Flare Atlas", _ProFlareBatch._atlas, typeof(ProFlareAtlas), false) as ProFlareAtlas;

        if (!_ProFlareBatch._atlas)
        {
            EditorGUILayout.HelpBox("Assign a Flare Atlas.", MessageType.Error, false);
        }


        Camera _camera = EditorGUILayout.ObjectField("Game Camera", _ProFlareBatch.GameCamera, typeof(Camera), true) as Camera;

        if (_camera != _ProFlareBatch.GameCamera)
        {
            Updated = true;

            _ProFlareBatch.GameCamera = _camera;

            if (_ProFlareBatch.GameCamera)
            {
                _ProFlareBatch.GameCameraTrans = _camera.transform;
            }
        }

        if (_ProFlareBatch.GameCamera == null)
        {
            EditorGUILayout.HelpBox("Assign Game Camera.", MessageType.Warning, false);
        }

        _ProFlareBatch.FlareCamera = EditorGUILayout.ObjectField("Flare Camera", _ProFlareBatch.FlareCamera, typeof(Camera), true) as Camera;

        Texture2D temp2D = null;

        if (_atlas != _ProFlareBatch._atlas)
        {
            if (_atlas == null)
            {
                _ProFlareBatch._atlas = null;
            }
            else
            if (_atlas.texture != null)
            {
                if (_ProFlareBatch.VR_Mode)
                {
                    _ProFlareBatch.name = "ProFlareBatch_VR (" + _atlas.gameObject.name + ")";
                }
                else
                {
                    _ProFlareBatch.name = "ProFlareBatch (" + _atlas.gameObject.name + ")";
                }

                _ProFlareBatch._atlas = _atlas;

                _ProFlareBatch.ForceRefresh();

                Updated = true;

                _ProFlareBatch.mat.mainTexture = _ProFlareBatch._atlas.texture;

                _ProFlareBatch.dirty = true;

                ProFlare[] flares = GameObject.FindObjectsOfType(typeof(ProFlare)) as ProFlare[];

                foreach (ProFlare flare in flares)
                {
                    flare.ReInitialise();
                }
            }
            else
            {
                Debug.LogError("ProFlares - Atlas missing texture, Atlas not assigned.");
            }
        }

        if (_ProFlareBatch.mode == ProFlareBatch.Mode.VR)
        {
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("VR Flare Depth");

            _ProFlareBatch.VR_Depth = EditorGUILayout.Slider(_ProFlareBatch.VR_Depth, 0f, 1f);

            EditorGUILayout.EndHorizontal();
        }

        if (_ProFlareBatch._atlas)
        {
            if (_ProFlareBatch.mat)
            {
                if (Application.isPlaying || (_ProFlareBatch.mat.mainTexture == null))
                {
                    if (_atlas.texture != null)
                    {
                        _ProFlareBatch.mat.mainTexture = _atlas.texture;
                    }
                }
            }


            FlareEditorHelper.DrawGuiDivider();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Connected Flares :", title);
            if (GUILayout.Button("Force Refresh", GUILayout.MaxWidth(120)))
            {
                _ProFlareBatch.ForceRefresh();

                ProFlare[] flares = GameObject.FindObjectsOfType(typeof(ProFlare)) as ProFlare[];

                foreach (ProFlare flare in flares)
                {
                    flare.ReInitialise();
                }

                Updated = true;
            }
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(9f);
//			if(_ProFlareBatch.Flares.Count != ProFlareBatch.FlaresList.Count){


//			}

            if (_ProFlareBatch.FlaresList.Count < 1)
            {
                EditorGUILayout.LabelField("No Connected flares");
            }
            else
            {
                EditorGUILayout.LabelField(_ProFlareBatch.FlaresList.Count.ToString() + " Flares Connected");

                if (_ProFlareBatch.FlaresList.Count < 10)
                {
                    _ProFlareBatch.showAllConnectedFlares = EditorGUILayout.Toggle("Show All Connected Flares", _ProFlareBatch.showAllConnectedFlares);
                }
                for (int i = 0; i < _ProFlareBatch.FlaresList.Count; i++)
                {
                    if (_ProFlareBatch.FlaresList[i].flare == null)
                    {
                        continue;
                    }

                    EditorGUILayout.BeginHorizontal();

                    if (_ProFlareBatch.FlaresList[i].occlusion == null)
                    {
                        continue;
                    }

                    if (!_ProFlareBatch.FlaresList[i].occlusion.occluded)
                    {
                        EditorGUILayout.LabelField((i + 1).ToString() + " - " + _ProFlareBatch.FlaresList[i].flare.gameObject.name + " - " + _ProFlareBatch.FlaresList[i].occlusion._CullingState.ToString());
                    }
                    else
                    {
                        EditorGUILayout.LabelField((i + 1).ToString() + " - " + _ProFlareBatch.FlaresList[i].flare.gameObject.name + " - " + _ProFlareBatch.FlaresList[i].occlusion._CullingState.ToString() + " - " + occluded);
                    }

                    if (GUILayout.Button("Select", GUILayout.Width(60)))
                    {
                        Selection.activeGameObject = _ProFlareBatch.FlaresList[i].flare.gameObject;
                    }


                    EditorGUILayout.EndHorizontal();
                    if (i > 10)
                    {
                        if (!_ProFlareBatch.showAllConnectedFlares)
                        {
                            break;
                        }
                    }
                }
            }

            FlareEditorHelper.DrawGuiDivider();
            EditorGUILayout.LabelField("Settings :", title);
            GUILayout.Space(9f);
            _ProFlareBatch.zPos = EditorGUILayout.FloatField("Z Position", _ProFlareBatch.zPos);
            FlareEditorHelper.DrawGuiDivider();
            EditorGUILayout.LabelField("Optimizations :", title);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Use Flare Culling");
            _ProFlareBatch.useCulling = EditorGUILayout.Toggle(_ProFlareBatch.useCulling);
            GUI.enabled = _ProFlareBatch.useCulling;
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Cull Flares After Seconds ");
            _ProFlareBatch.cullFlaresAfterTime = EditorGUILayout.IntField(_ProFlareBatch.cullFlaresAfterTime);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Cull Flares when can cull # Flares ");
            _ProFlareBatch.cullFlaresAfterCount = EditorGUILayout.IntField(_ProFlareBatch.cullFlaresAfterCount);
            EditorGUILayout.EndHorizontal();

            GUI.enabled = true;
            GUILayout.Space(8f);
            EditorGUILayout.BeginVertical("box");
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Use Brightness Culling");
            _ProFlareBatch.useBrightnessThreshold = EditorGUILayout.Toggle(_ProFlareBatch.useBrightnessThreshold);
            EditorGUILayout.EndHorizontal();
            GUI.enabled = _ProFlareBatch.useBrightnessThreshold;
            _ProFlareBatch.BrightnessThreshold = Mathf.Clamp(EditorGUILayout.IntField("   Minimum Brightness", _ProFlareBatch.BrightnessThreshold), 0, 255);
            GUI.enabled = true;

            EditorGUILayout.EndVertical();


            if (Application.isPlaying)
            {
                GUI.enabled = false;
            }
            else
            {
                GUI.enabled = true;
            }

            FlareEditorHelper.DrawGuiDivider();

            EditorGUILayout.LabelField("Debug :", title);
            GUILayout.Space(8f);

            EditorGUILayout.BeginVertical("box");
            EditorGUILayout.LabelField("Flare Count : " + _ProFlareBatch.FlaresList.Count);
            EditorGUILayout.LabelField("Flare Elements : " + _ProFlareBatch.FlareElements.Count);
            //if(_ProFlareBatch.meshFilter){
            //	EditorGUILayout.LabelField("Triangle Count : " + (_ProFlareBatch.meshFilter.sharedMesh.triangles.Length/3).ToString());
            //	EditorGUILayout.LabelField("Vertex Count : " + _ProFlareBatch.meshFilter.sharedMesh.vertexCount.ToString());
            //}
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Show Overdraw", GUILayout.MaxWidth(160));
            //_ProFlareBatch.useBrightnessThreshold = EditorGUILayout.Toggle(_ProFlareBatch.useBrightnessThreshold);
            bool overdraw = EditorGUILayout.Toggle(_ProFlareBatch.overdrawDebug);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();



            if (overdraw != _ProFlareBatch.overdrawDebug)
            {
                _ProFlareBatch.overdrawDebug = overdraw;

                if (overdraw)
                {
                    temp2D           = new Texture2D(1, 16);
                    temp2D.name      = "[Generated] Debug";
                    temp2D.hideFlags = HideFlags.DontSave;

                    for (int i = 0; i < 16; ++i)
                    {
                        temp2D.SetPixel(0, i, Color.white);
                    }

                    _ProFlareBatch.mat.mainTexture = temp2D;
                }
                else
                {
                    if (_atlas.texture != null)
                    {
                        _ProFlareBatch.mat.mainTexture = _atlas.texture;
                    }

                    if (temp2D != null)
                    {
                        Destroy(temp2D);
                    }
                }
            }
            FlareEditorHelper.DrawGuiDivider();

            if (GUI.changed || Updated)
            {
                Updated = false;
                EditorUtility.SetDirty(target);
            }
        }
    }