public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
            {
                if (attribute._label != null) label.text = attribute._label;

                if (attribute._target == null)
                {
                    attribute._target = property.serializedObject.targetObject;
                    attribute._propertyInfo = ReflectionKit.GetPropertyInfo(attribute._target, attribute._propertyName);
                }

                if (attribute._propertyInfo == null)
                {
                    EditorGUI.LabelField(position, label.text, "Can't find property");
                    return;
                }

                if (fieldInfo.FieldType != attribute._propertyInfo.PropertyType)
                {
                    EditorGUI.LabelField(position, label.text, "Mismatching property type");
                    return;
                }

                if (!attribute._propertyInfo.CanRead || !attribute._propertyInfo.CanWrite)
                {
                    EditorGUI.LabelField(position, label.text, "Property can't read or write");
                    return;
                }

                using (var scope = new ChangeCheckScope(property.serializedObject.targetObject))
                {
                    object value = attribute._propertyInfo.GetValue(attribute._target, null);

                    switch (property.propertyType)
                    {
                        case SerializedPropertyType.AnimationCurve:
                            {
                                value = EditorGUI.CurveField(position, label, (AnimationCurve)value);
                                break;
                            }
                        case SerializedPropertyType.Boolean:
                            {
                                value = EditorGUI.Toggle(position, label, (bool)value);
                                break;
                            }
                        case SerializedPropertyType.Bounds:
                            {
                                value = EditorGUI.BoundsField(position, label, (Bounds)value);
                                break;
                            }
                        case SerializedPropertyType.Color:
                            {
                                value = EditorGUI.ColorField(position, label, (Color)value);
                                break;
                            }
                        case SerializedPropertyType.Enum:
                            {
                                value = EditorGUI.EnumPopup(position, label, (System.Enum)value);
                                break;
                            }
                        case SerializedPropertyType.Float:
                            {
                                value = EditorGUI.FloatField(position, label, (float)value);
                                break;
                            }
                        case SerializedPropertyType.Integer:
                            {
                                value = EditorGUI.IntField(position, label, (int)value);
                                break;
                            }
                        case SerializedPropertyType.ObjectReference:
                            {
                                value = EditorGUI.ObjectField(position, label, value as Object, fieldInfo.FieldType, !EditorUtility.IsPersistent(attribute._target));
                                break;
                            }
                        case SerializedPropertyType.Rect:
                            {
                                value = EditorGUI.RectField(position, label, (Rect)value);
                                break;
                            }
                        case SerializedPropertyType.String:
                            {
                                value = EditorGUI.TextField(position, label, (string)value);
                                break;
                            }
                        case SerializedPropertyType.Vector2:
                            {
                                value = EditorGUI.Vector2Field(position, label, (Vector2)value);
                                break;
                            }
                        case SerializedPropertyType.Vector3:
                            {
                                value = EditorGUI.Vector3Field(position, label, (Vector3)value);
                                break;
                            }
                        case SerializedPropertyType.Vector4:
                            {
                                value = EditorGUI.Vector4Field(position, label.text, (Vector4)value);
                                break;
                            }
                        default:
                            {
                                EditorGUI.LabelField(position, label.text, "Type is not supported");
                                break;
                            }
                    }

                    if (scope.changed) attribute._propertyInfo.SetValue(attribute._target, value, null);
                }

            } // OnGUI
 private static void DrawColorField(SerializedProperty serializedProperty, float x, float y, float colorWidth, float height)
 {
     serializedProperty.colorValue = EditorGUI.ColorField(new Rect(x, y, colorWidth, height), GUIContent.none, serializedProperty.colorValue, false, false, false);
 }
        private void OnGUIDrawItems(Rect rect, Func <Rect> next)
        {
            EditorGUI.LabelField(rect, "Point Settings", EditorStyles.boldLabel);

            EditorGUIChangeCheck(() =>
            {
                // Mesh
                rect = next();
                _property.baseMesh = (Mesh)EditorGUI.ObjectField(rect, "Target Mesh", _property.baseMesh, typeof(Mesh), true);

                // UV Type
                rect             = next();
                _property.uvType = (PointBuilder.UVType)EditorGUI.EnumPopup(rect, "UV Type", _property.uvType);
            }, OnChangeMeshUV);

            EditorGUIChangeCheck(() =>
            {
                // uv interval
                rect = next();
                _property.uvDivision = EditorGUI.Vector2IntField(rect, "UV Division", _property.uvDivision);

                rect = next();
                rect = next();
                _property.uvOffset = EditorGUI.Vector2Field(rect, "UV Offset", _property.uvOffset);
            }, OnChangePointBuilderSettings);

            // preview

            rect = next();
            rect = next();
            rect = next();
            EditorGUI.LabelField(rect, "Preview", EditorStyles.boldLabel);

            /*
             * rect.y += itemHeight + 2;
             * _uvPreviewPosition = EditorGUI.Vector3Field(rect, "UV Position", _uvPreviewPosition);
             *
             * rect.y += itemHeight * 2 + 2;
             * _pointMeshPreviewPosition = EditorGUI.Vector3Field(rect, "Point Position", _pointMeshPreviewPosition);
             *
             * rect.y += itemHeight * 2 + 2;
             * _pointMeshPreviewEuler = EditorGUI.Vector3Field(rect, "Point Euler", _pointMeshPreviewEuler);
             */

            EditorGUIChangeCheck(() =>
            {
                rect = next();
                _property.wireSize = EditorGUI.Slider(rect, "Wire Size", _property.wireSize, 0, 0.34f);

                //_pointSize = EditorGUI.IntSlider(rect, "Point Size", _pointSize, 1, 10);

                rect = next();
                _property.wireColor = EditorGUI.ColorField(rect, "Wire Color", _property.wireColor);

                rect = next();
                _property.pointColor = EditorGUI.ColorField(rect, "Point Color", _property.pointColor);
            }, OnChangePreviewMaterial);

            rect = next();
            if (GUI.Button(rect, "Preview Camera Reset"))
            {
                OnClickPreviewResetButton();
            }

            rect = next();
            if (GUI.Button(rect, "Build Preview"))
            {
                OnClickPreviewButton();
            }

            // Export
            EditorGUIChangeCheck(() =>
            {
                rect = next();
                rect = next();
                EditorGUI.LabelField(rect, "Export", EditorStyles.boldLabel);

                rect = next();
                _property.exportDir = EditorGUI.TextField(rect, "Export Dir", _property.exportDir);

                rect = next();
                _property.exportNamePrefix = EditorGUI.TextField(rect, "Export Name Prefix", _property.exportNamePrefix);
            }, OnChangeProperty);

            rect = next();
            if (GUI.Button(rect, "Export Point Mesh"))
            {
                OnClickExportPointMesh();
            }
        }
    public override void OnInspectorGUI()
    {
        //string renName = "";
        //int setRename = 0;
        //int localPresetIndex = -1;

        //bool showErrors = false;
        //bool showPresets = false;
        //bool showSplash = false;
        //bool showWaves = false;
        //bool showGeneral = false;
        //bool showSurface = false;
        //bool showUnderwater = false;
        //bool showEffects = false;
        //bool showColor = false;
        //bool showReflect = false;
        //bool showFoam = false;

        Texture logoTex;
        Texture divTex;
        Texture divRevTex;
        //Texture divVertTex;
        //Texture divHorizTex;
        //Texture bgPreset;
        //Texture bgPresetSt;
        //Texture bgPresetNd;

        Color colorEnabled  = new Color(1.0f, 1.0f, 1.0f, 1.0f);
        Color colorDisabled = new Color(1.0f, 1.0f, 1.0f, 0.25f);

        //Color colorEnabled = new Color(1.0f,1.0f,1.0f,1.0f);
        //Color colorDisabled = new Color(1.0f,1.0f,1.0f,0.35f);
        //Color highlightColor2 = new Color(0.7f,1f,0.2f,0.6f);
        //Color highlightColor = new Color(1f,0.5f,0f,0.9f);

        float emMin = 1.0f;
        float emMax = 3.0f;
        float aMin  = 0.9f;
        float aMax  = 1.0f;
        float apMin = 0.9f;
        float apMax = 1.1f;
        float szMin = 0.5f;
        float szMax = 1.5f;



        Suimono.Core.fx_EffectObject script = (Suimono.Core.fx_EffectObject)target;
        Undo.RecordObject(target, "Changed Area Of Effect");



        //load textures
        logoTex   = Resources.Load("textures/gui_tex_suimonologo_i") as Texture;
        divTex    = Resources.Load("textures/gui_tex_suimonodiv_i") as Texture;
        divRevTex = Resources.Load("textures/gui_tex_suimonodivrev_i") as Texture;


        if (EditorGUIUtility.isProSkin == true)
        {
            divTex    = Resources.Load("textures/gui_tex_suimonodiv") as Texture;
            logoTex   = Resources.Load("textures/gui_tex_suimonologofx") as Texture;
            divRevTex = Resources.Load("textures/gui_tex_suimonodivrev") as Texture;
        }


        //SUIMONO LOGO
        GUIContent buttonText  = new GUIContent("");
        GUIStyle   buttonStyle = GUIStyle.none;
        Rect       rt          = GUILayoutUtility.GetRect(buttonText, buttonStyle);
        int        margin      = 15;

        EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 36), logoTex);

        GUILayout.Space(25.0f);



        //SET TYPE
        rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
        EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 24), divTex);
        //EditorGUI.DrawPreviewTexture(new Rect(rt.x+margin,rt.y+30,387,24),divRevTex);

        //if (GUI.Button(new Rect(rt.x+margin,rt.y+12,192,24),"Particle Effect")) script.typeIndex = 0;
        //if (GUI.Button(new Rect(rt.x+margin+194,rt.y+12,192,24),"Audio Effect")) script.typeIndex = 1;

        if (GUI.Button(new Rect(rt.x + margin, rt.y + 12, 128, 24), "Particle Effect"))
        {
            script.typeIndex = 0;
        }
        if (GUI.Button(new Rect(rt.x + margin + 130, rt.y + 12, 128, 24), "Audio Effect"))
        {
            script.typeIndex = 1;
        }
        if (GUI.Button(new Rect(rt.x + margin + 130 * 2, rt.y + 12, 128, 24), "Event Trigger"))
        {
            script.typeIndex = 2;
        }


        GUILayout.Space(30.0f);



        //SET ACTION TYPE
        rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
        EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 24), divTex);

        EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 12, 180, 18), "Action Type");
        script.actionIndex = EditorGUI.Popup(new Rect(rt.x + margin + 110, rt.y + 12, 260, 18), "", script.actionIndex, script.actionOptions.ToArray());

        if (script.actionIndex == 0 || script.actionIndex == 2)
        {
            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 32, 90, 18), "Reset Time");
            script.actionReset = EditorGUI.FloatField(new Rect(rt.x + margin + 110, rt.y + 32, 40, 18), "", script.actionReset);

            if (script.actionIndex == 2)
            {
                EditorGUI.LabelField(new Rect(rt.x + margin + 225, rt.y + 32, 100, 18), "Repeat Number");
                script.actionNum = EditorGUI.IntField(new Rect(rt.x + margin + 325, rt.y + 32, 40, 18), "", script.actionNum);
            }
            GUILayout.Space(20.0f);
        }

        GUILayout.Space(20.0f);



        //SET EFFECT PARTICLE UI
        if (script.typeIndex == 0)
        {
            rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 24), divTex);
            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y + 139, 387, 24), divRevTex);

            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 15, 90, 18), "Particle Effect");

            script.systemIndex = EditorGUI.Popup(new Rect(rt.x + margin + 110, rt.y + 15, 260, 18), "", script.systemIndex, script.sysNames.ToArray());
            //script.systemIndex = EditorGUI.Popup(new Rect(rt.x+margin+110, rt.y+15, 260, 18),"",script.systemIndex, script.sysNames);


            emMin = script.emitNum.x;
            emMax = script.emitNum.y;
            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 45, 130, 18), "Emit Number");
            EditorGUI.MinMaxSlider(new Rect(rt.x + margin + 115, rt.y + 45, 200, 18), ref emMin, ref emMax, 0.0f, 20.0f);
            EditorGUI.LabelField(new Rect(rt.x + margin + 340, rt.y + 45, 50, 18), Mathf.Floor(emMin) + "  " + Mathf.Floor(emMax));

            szMin = script.effectSize.x;
            szMax = script.effectSize.y;
            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 65, 130, 18), "Particle Size");
            EditorGUI.MinMaxSlider(new Rect(rt.x + margin + 115, rt.y + 65, 200, 18), ref szMin, ref szMax, 0.0f, 4.0f);
            EditorGUI.LabelField(new Rect(rt.x + margin + 340, rt.y + 65, 50, 18), szMin.ToString("F1") + "  " + szMax.ToString("F1"));



            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 95, 130, 18), "Emission Speed");
            script.emitSpeed = EditorGUI.FloatField(new Rect(rt.x + margin + 115, rt.y + 95, 60, 18), "", script.emitSpeed);

            EditorGUI.LabelField(new Rect(rt.x + margin + 210, rt.y + 95, 130, 18), "Directional Speed");
            script.directionMultiplier = EditorGUI.FloatField(new Rect(rt.x + margin + 320, rt.y + 95, 40, 18), "", script.directionMultiplier);

            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 115, 130, 18), "Emit At Surface");
            script.emitAtWaterLevel = EditorGUI.Toggle(new Rect(rt.x + margin + 115, rt.y + 114, 40, 18), "", script.emitAtWaterLevel);

            EditorGUI.LabelField(new Rect(rt.x + margin + 210, rt.y + 115, 130, 18), "Distance Range");
            script.effectDistance = EditorGUI.FloatField(new Rect(rt.x + margin + 320, rt.y + 114, 40, 18), "", script.effectDistance);

            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 135, 130, 18), "Clamp Rotation");
            script.clampRot = EditorGUI.Toggle(new Rect(rt.x + margin + 115, rt.y + 134, 40, 18), "", script.clampRot);

            EditorGUI.LabelField(new Rect(rt.x + margin + 155, rt.y + 135, 130, 18), "Tint Color");
            script.tintCol = EditorGUI.ColorField(new Rect(rt.x + margin + 225, rt.y + 134, 140, 18), "", script.tintCol);

            script.emitNum.x    = Mathf.Floor(emMin);
            script.emitNum.y    = Mathf.Floor(emMax);
            script.effectSize.x = szMin;
            script.effectSize.y = szMax;

            GUILayout.Space(150.0f);
        }


        //SET EFFECT AUDIO UI
        if (script.typeIndex == 1)
        {
            rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 24), divTex);
            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y + 139, 387, 24), divRevTex);

            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 15, 130, 18), "Select Audio Sample");
            script.audioObj = EditorGUI.ObjectField(new Rect(rt.x + margin + 150, rt.y + 15, 220, 18), script.audioObj, typeof(AudioClip), true) as AudioClip;

            aMin = script.audioVol.x;
            aMax = script.audioVol.y;
            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 45, 130, 18), "Audio Volume Range");
            EditorGUI.MinMaxSlider(new Rect(rt.x + margin + 150, rt.y + 45, 230, 18), ref aMin, ref aMax, 0.0f, 1.0f);

            apMin = script.audioPit.x;
            apMax = script.audioPit.y;
            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 65, 130, 18), "Audio Pitch Range");
            EditorGUI.MinMaxSlider(new Rect(rt.x + margin + 150, rt.y + 65, 230, 18), ref apMin, ref apMax, 0.0f, 2.0f);

            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 90, 150, 18), "Audio Repeat Speed");
            script.audioSpeed = EditorGUI.FloatField(new Rect(rt.x + margin + 145, rt.y + 90, 60, 18), "", script.audioSpeed);


            script.audioVol.x = aMin;
            script.audioVol.y = aMax;
            script.audioPit.x = apMin;
            script.audioPit.y = apMax;

            GUILayout.Space(150.0f);
        }



        //SET EVENT UI
        if (script.typeIndex == 2)
        {
            rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 24), divTex);
            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y + 139, 387, 24), divRevTex);

            GUI.contentColor    = colorDisabled;
            GUI.backgroundColor = colorDisabled;
            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 10, 387, 18), "*Event will be triggered REGARDLESS of action type*");
            GUI.contentColor    = colorEnabled;
            GUI.backgroundColor = colorEnabled;


            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 30, 130, 18), "Enable Event Broadcasting");
            script.enableEvents = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 30, 40, 18), "", script.enableEvents);


            if (!script.enableEvents)
            {
                GUI.contentColor    = colorDisabled;
                GUI.backgroundColor = colorDisabled;
            }

            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 60, 130, 18), "Interval(sec)");
            script.eventInterval = EditorGUI.FloatField(new Rect(rt.x + margin + 115, rt.y + 60, 30, 18), "", script.eventInterval);
            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 80, 130, 18), "At Surface");
            script.eventAtSurface = EditorGUI.Toggle(new Rect(rt.x + margin + 115, rt.y + 80, 40, 18), "", script.eventAtSurface);

            GUI.contentColor    = colorEnabled;
            GUI.backgroundColor = colorEnabled;

            GUILayout.Space(150.0f);
        }



        //SET RULES
        rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
        EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 24), divTex);
        EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y + 89f + (script.effectRule.Length * 20.0f), 387f, 24f), divRevTex);

        EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 15, 387, 18), "SET ACTIVATION RULES");

        if (script.effectRule.Length <= 0)
        {
            EditorGUI.LabelField(new Rect(rt.x + margin + 50, rt.y + 35, 387, 18), "THERE ARE CURRENTLY NO RULES TO VIEW...");
        }
        else
        {
            for (int rL = 0; rL < script.effectRule.Length; rL++)
            {
                if (rL < script.effectRule.Length)
                {
                    if (GUI.Button(new Rect(rt.x + margin + 10f, rt.y + 45f + (rL * 20.0f), 18f, 16f), "-"))
                    {
                        script.DeleteRule(rL);
                    }

                    if (rL >= script.effectRule.Length)
                    {
                        break;
                    }

                    EditorGUI.LabelField(new Rect(rt.x + margin + 35f, rt.y + 45f + (rL * 20.0f), 70f, 18f), "RULE " + (rL + 1));

                    //-----------------
                    if (script.ruleIndex[rL] > 3 && script.ruleIndex[rL] < 8)
                    {
                        script.ruleIndex[rL]  = EditorGUI.Popup(new Rect(rt.x + margin + 90f, rt.y + 45f + (rL * 20.0f), 246f, 18f), "", script.ruleIndex[rL], script.ruleOptions.ToArray());
                        script.effectData[rL] = EditorGUI.FloatField(new Rect(rt.x + margin + 340f, rt.y + 44f + (rL * 20.0f), 30f, 18f), "", script.effectData[rL]);
                    }
                    else
                    {
                        script.ruleIndex[rL] = EditorGUI.Popup(new Rect(rt.x + margin + 90f, rt.y + 45f + (rL * 20.0f), 280f, 18f), "", script.ruleIndex[rL], script.ruleOptions.ToArray());
                    }
                    //-----------------

                    GUILayout.Space(20.0f);
                }
            }
        }

        if (GUI.Button(new Rect(rt.x + margin + 90f, rt.y + 60f + (script.effectRule.Length * 20.0f), 200f, 18f), "+ ADD NEW RULE"))
        {
            script.AddRule();
        }

        GUILayout.Space(100.0f);

        EditorUtility.SetDirty(script);
    }
        static void drawItem(Rect rect, int index, bool isActive, bool isFocused)
        {
            if (m_Attributes[index] == null)
            {
                var color = GUI.color;
                GUI.color = Color.red;
                EditorGUI.LabelField(rect, "NULL OR DELETED");
                GUI.color = color;
                return;
            }

            rect.yMin  += 2;
            rect.height = 16;

            var namerect = rect;

            namerect.width = 100;

            m_Attributes[index].name = GUI.TextField(namerect, m_Attributes[index].name);

            var typerect = rect;

            typerect.xMin            = rect.xMin + 108;
            typerect.width           = 64;
            m_Attributes[index].type = (EventAttributeType)EditorGUI.EnumPopup(typerect, m_Attributes[index].type);

            var valueRect = rect;

            valueRect.xMin = rect.xMin + 180;
            switch (m_Attributes[index].type)
            {
            case EventAttributeType.Bool:
                if (m_Attributes[index].value == null || !(m_Attributes[index].value is bool))
                {
                    m_Attributes[index].value = true;
                }

                m_Attributes[index].value = (bool)EditorGUI.Toggle(valueRect, (bool)m_Attributes[index].value);
                break;

            case EventAttributeType.Float:
                if (m_Attributes[index].value == null || !(m_Attributes[index].value is float))
                {
                    m_Attributes[index].value = 1.0f;
                }

                m_Attributes[index].value = (float)EditorGUI.FloatField(valueRect, (float)m_Attributes[index].value);
                break;

            case EventAttributeType.Vector2:
                if (m_Attributes[index].value == null || !(m_Attributes[index].value is Vector2))
                {
                    m_Attributes[index].value = Vector2.zero;
                }

                m_Attributes[index].value = (Vector2)EditorGUI.Vector2Field(valueRect, "", (Vector2)m_Attributes[index].value);
                break;

            case EventAttributeType.Vector3:
                if (m_Attributes[index].value == null || !(m_Attributes[index].value is Vector3))
                {
                    m_Attributes[index].value = Vector3.zero;
                }

                m_Attributes[index].value = (Vector3)EditorGUI.Vector3Field(valueRect, "", (Vector3)m_Attributes[index].value);
                break;

            case EventAttributeType.Color:
                if (m_Attributes[index].value == null || !(m_Attributes[index].value is Color))
                {
                    m_Attributes[index].value = Color.white;
                }

                m_Attributes[index].value = (Color)EditorGUI.ColorField(valueRect, (Color)m_Attributes[index].value);
                break;
            }
        }
        private void OnEnable()
        {
            Action <ReorderableList, SerializedProperty> fnAssetDropDown = delegate(ReorderableList list, SerializedProperty property)
            {
                var existingAttribute = new List <string>();
                for (int i = 0; i < property.arraySize; ++i)
                {
                    existingAttribute.Add(property.GetArrayElementAtIndex(i).FindPropertyRelative("attribute.m_Name").stringValue);
                }

                var menu = new GenericMenu();
                foreach (var attributeName in VFXAttribute.AllIncludingVariadicReadWritable.Except(existingAttribute).OrderBy(o => o))
                {
                    var attribute = VFXAttribute.Find(attributeName);
                    menu.AddItem(new GUIContent(attribute.name), false, () =>
                    {
                        serializedObject.Update();
                        property.arraySize++;

                        var newElement = property.GetArrayElementAtIndex(property.arraySize - 1);
                        newElement.FindPropertyRelative("attribute.m_Name").stringValue = attribute.name;
                        newElement.FindPropertyRelative("type").intValue = (int)attribute.type;

                        var size         = VFXExpression.TypeToSize(attribute.type);
                        var values       = newElement.FindPropertyRelative("values");
                        values.arraySize = size;

                        var initialValues = new float[size];
                        if (attribute.type == VFXValueType.Float)
                        {
                            initialValues[0] = attribute.value.Get <float>();
                        }
                        else if (attribute.type == VFXValueType.Float2)
                        {
                            var v            = attribute.value.Get <Vector2>();
                            initialValues[0] = v.x;
                            initialValues[1] = v.y;
                        }
                        else if (attribute.type == VFXValueType.Float3)
                        {
                            var v            = attribute.value.Get <Vector3>();
                            initialValues[0] = v.x;
                            initialValues[1] = v.y;
                            initialValues[2] = v.z;
                        }
                        else if (attribute.type == VFXValueType.Float4)
                        {
                            var v            = attribute.value.Get <Vector4>();
                            initialValues[0] = v.x;
                            initialValues[1] = v.y;
                            initialValues[2] = v.z;
                            initialValues[3] = v.w;
                        }
                        else if (attribute.type == VFXValueType.Int32)
                        {
                            initialValues[0] = attribute.value.Get <int>();
                        }
                        else if (attribute.type == VFXValueType.Uint32)
                        {
                            initialValues[0] = attribute.value.Get <uint>();
                        }
                        else if (attribute.type == VFXValueType.Boolean)
                        {
                            initialValues[0] = attribute.value.Get <bool>() ? 1.0f : 0.0f;
                        }
                        for (int i = 0; i < size; ++i)
                        {
                            values.GetArrayElementAtIndex(i).floatValue = initialValues[i];
                        }
                        serializedObject.ApplyModifiedProperties();
                    });
                }
                menu.ShowAsContext();
            };

            Action <Rect, SerializedProperty, int> fnDrawElement = delegate(Rect r, SerializedProperty property, int index)
            {
                var element = property.GetArrayElementAtIndex(index);

                var label      = element.FindPropertyRelative("attribute.m_Name").stringValue;
                var labelWidth = 110;//GUI.skin.label.CalcSize(new GUIContent(label)); //Should be maximized among all existing property, for now, angularVelocity is considered as maximum

                EditorGUI.LabelField(new Rect(r.x, r.y, labelWidth, EditorGUIUtility.singleLineHeight), label);
                var valueType       = (VFXValueType)element.FindPropertyRelative("type").intValue;
                var valueSize       = VFXExpression.TypeToSize(valueType);
                var fieldWidth      = (r.width - labelWidth) / valueSize;
                var emptyGUIContent = new GUIContent(string.Empty);
                var valuesProperty  = element.FindPropertyRelative("values");
                if (valueType == VFXValueType.Float ||
                    valueType == VFXValueType.Float2 ||
                    valueType == VFXValueType.Float3 ||
                    valueType == VFXValueType.Float4)
                {
                    if (label.Contains("color") && valueType == VFXValueType.Float3)
                    {
                        var oldColor = new Color(valuesProperty.GetArrayElementAtIndex(0).floatValue,
                                                 valuesProperty.GetArrayElementAtIndex(1).floatValue,
                                                 valuesProperty.GetArrayElementAtIndex(2).floatValue);

                        EditorGUI.BeginChangeCheck();
                        var newColor = EditorGUI.ColorField(new Rect(r.x + labelWidth, r.y, fieldWidth * 3, EditorGUIUtility.singleLineHeight), oldColor);
                        if (EditorGUI.EndChangeCheck())
                        {
                            valuesProperty.GetArrayElementAtIndex(0).floatValue = newColor.r;
                            valuesProperty.GetArrayElementAtIndex(1).floatValue = newColor.g;
                            valuesProperty.GetArrayElementAtIndex(2).floatValue = newColor.b;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < valueSize; ++i)
                        {
                            EditorGUI.PropertyField(new Rect(r.x + labelWidth + fieldWidth * i, r.y, fieldWidth, EditorGUIUtility.singleLineHeight), valuesProperty.GetArrayElementAtIndex(i), emptyGUIContent);
                        }
                    }
                }
                else if (valueType == VFXValueType.Int32 ||
                         valueType == VFXValueType.Uint32 ||
                         valueType == VFXValueType.Boolean)
                {
                    var   oldValue = valuesProperty.GetArrayElementAtIndex(0).floatValue;
                    float newValue;
                    var   currentRect = new Rect(r.x + labelWidth, r.y, fieldWidth, EditorGUIUtility.singleLineHeight);
                    EditorGUI.BeginChangeCheck();
                    if (valueType == VFXValueType.Boolean)
                    {
                        newValue = EditorGUI.Toggle(currentRect, emptyGUIContent, oldValue != 0.0f) ? 1.0f : 0.0f;
                    }
                    else
                    {
                        newValue = (float)EditorGUI.LongField(currentRect, emptyGUIContent, (long)oldValue);
                        newValue = newValue < 0.0f ? 0.0f : newValue;
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        valuesProperty.GetArrayElementAtIndex(0).floatValue = newValue;
                        serializedObject.ApplyModifiedProperties();
                    }
                }
            };

            onClipEnterProperty = serializedObject.FindProperty("activationBehavior.onClipEnter.m_Name");
            onClipExitProperty  = serializedObject.FindProperty("activationBehavior.onClipExit.m_Name");

            var clipEnterAttributesProperty = serializedObject.FindProperty("activationBehavior.clipEnterEventAttributes");
            var clipExitAttributesProperty  = serializedObject.FindProperty("activationBehavior.clipExitEventAttributes");

            clipEnterAttributesPropertyList = new ReorderableList(serializedObject, clipEnterAttributesProperty, true, true, true, true);
            clipExitAttributesPropertyList  = new ReorderableList(serializedObject, clipExitAttributesProperty, true, true, true, true);

            clipEnterAttributesPropertyList.drawHeaderCallback = (Rect r) => { EditorGUI.LabelField(r, "Enter Event Attributes"); };
            clipExitAttributesPropertyList.drawHeaderCallback  = (Rect r) => { EditorGUI.LabelField(r, "Exit Event Attributes"); };

            clipEnterAttributesPropertyList.onAddDropdownCallback += (Rect buttonRect, ReorderableList list) => fnAssetDropDown(list, clipEnterAttributesProperty);
            clipExitAttributesPropertyList.onAddDropdownCallback  += (Rect buttonRect, ReorderableList list) => fnAssetDropDown(list, clipExitAttributesProperty);

            clipEnterAttributesPropertyList.drawElementCallback = (Rect r, int index, bool active, bool focused) => fnDrawElement(r, clipEnterAttributesProperty, index);
            clipExitAttributesPropertyList.drawElementCallback  = (Rect r, int index, bool active, bool focused) => fnDrawElement(r, clipExitAttributesProperty, index);
        }
Beispiel #7
0
        private void OnEnable()
        {
            MemoryItems = serializedObject.FindProperty("MemoryItems");
            memoryfield = MoonReflection.GetField("memory", target);

            MemoryList = new ReorderableList(serializedObject, MemoryItems, true, true, true, true);
            MemoryList.elementHeight      = 50;
            MemoryList.drawHeaderCallback = (Rect r) =>
            {
                EditorGUI.LabelField(r, new GUIContent("Memory Elements", "User pre-defined memory elements"));
            };

            MemoryList.drawElementCallback = (Rect rect, int index, bool isactive, bool isfocused) =>
            {
                SerializedProperty current = MemoryItems.GetArrayElementAtIndex(index);

                Rect toprect = new Rect(rect.x, rect.y + 2, rect.width, 20);

                SerializedProperty type = current.FindPropertyRelative("type");

                ItemType itype = (ItemType)type.enumValueIndex;

                // key gui

                GUI.BeginGroup(toprect);


                GUIContent labelcont = new GUIContent(MemoryItem.ConvertType(itype).Name);

                float w = GUI.skin.FindStyle("AssetLabel").CalcSize(labelcont).x;

                GUI.Label(new Rect(0, 0, w, 16), labelcont, GUI.skin.FindStyle("AssetLabel"));

                GUI.Label(new Rect(w + 5, 0, 30, 16), "key:");

                SerializedProperty key = current.FindPropertyRelative("Key");

                key.stringValue = EditorGUI.TextField(new Rect(w + 40, 0, toprect.width - (w + 40), 16), key.stringValue);

                GUI.EndGroup();

                // value gui

                Rect buttunrect = new Rect(rect.x, toprect.yMax + 2, rect.width, 20);

                GUI.BeginGroup(buttunrect);

                GUI.Label(new Rect(0, 0, 50, 15), "Value");

                Rect ValueRect = new Rect(60, 0, buttunrect.width - 60, 16);

                switch (itype)
                {
                case ItemType.BOOLEAN:

                    SerializedProperty BoolValue = current.FindPropertyRelative("BoolValue");

                    BoolValue.boolValue = EditorGUI.Toggle(new Rect(ValueRect.position, Vector2.one * 16), BoolValue.boolValue);

                    break;

                case ItemType.STRING:

                    SerializedProperty StringValue = current.FindPropertyRelative("StringValue");

                    StringValue.stringValue = EditorGUI.TextField(ValueRect, StringValue.stringValue);

                    break;

                case ItemType.FLOAT:

                    SerializedProperty floatValue = current.FindPropertyRelative("floatValue");

                    floatValue.floatValue = EditorGUI.FloatField(ValueRect, floatValue.floatValue);

                    break;

                case ItemType.INT:

                    SerializedProperty intValue = current.FindPropertyRelative("intValue");

                    intValue.intValue = EditorGUI.IntField(ValueRect, intValue.intValue);

                    break;

                case ItemType.VECTOR2:

                    SerializedProperty Vector2Value = current.FindPropertyRelative("Vector2Value");

                    Vector2Value.vector2Value = EditorGUI.Vector2Field(ValueRect, "", Vector2Value.vector2Value);

                    break;

                case ItemType.VECTOR3:

                    SerializedProperty Vector3Value = current.FindPropertyRelative("Vector3Value");

                    Vector3Value.vector3Value = EditorGUI.Vector3Field(ValueRect, "", Vector3Value.vector3Value);

                    break;

                case ItemType.VECTOR4:

                    SerializedProperty Vector4Value = current.FindPropertyRelative("Vector4Value");

                    Vector4Value.vector4Value = EditorGUI.Vector4Field(ValueRect, "", Vector4Value.vector4Value);

                    break;

                case ItemType.COLOR:

                    SerializedProperty ColorValue = current.FindPropertyRelative("ColorValue");

                    ColorValue.colorValue = EditorGUI.ColorField(ValueRect, ColorValue.colorValue);

                    break;

                case ItemType.OBJECT:

                    SerializedProperty objectValue = current.FindPropertyRelative("objectValue");

                    objectValue.objectReferenceValue = EditorGUI.ObjectField(ValueRect, "",
                                                                             objectValue.objectReferenceValue, typeof(Object), true);

                    break;

                case ItemType.LAYERMASK:

                    SerializedProperty LayerValue = current.FindPropertyRelative("LayerValue");

                    EditorGUI.PropertyField(ValueRect, LayerValue, GUIContent.none, true);

                    break;
                }


                GUI.EndGroup();
            };

            MemoryList.onAddDropdownCallback = (Rect btnrect, ReorderableList list) =>
            {
                int targetindex = list.serializedProperty.arraySize;

                GenericMenu menu = new GenericMenu();
                string[]    opcs = System.Enum.GetNames(typeof(ItemType));

                for (int i = 0; i < opcs.Length; i++)
                {
                    string elementName = opcs[i];
                    menu.AddItem(new GUIContent(elementName), false, new GenericMenu.MenuFunction(() =>
                    {
                        list.serializedProperty.InsertArrayElementAtIndex(targetindex);
                        serializedObject.ApplyModifiedProperties();
                        SerializedProperty current = MemoryItems.GetArrayElementAtIndex(targetindex);
                        SerializedProperty type    = current.FindPropertyRelative("type");

                        for (int j = 0; j < type.enumNames.Length; j++)
                        {
                            if (string.Equals(elementName, type.enumNames[j]))
                            {
                                list.serializedProperty.serializedObject.Update();
                                type.enumValueIndex = j;
                                current.FindPropertyRelative("Key").stringValue = string.Empty;
                                list.serializedProperty.serializedObject.ApplyModifiedProperties();
                                break;
                            }
                        }
                    }));
                }
                menu.DropDown(btnrect);
            };
        }
Beispiel #8
0
    /// <summary>
    /// 绘制object
    /// </summary>
    /// <param name="showName"></param>
    /// <param name="data"></param>
    /// <returns></returns>
    public static object DrawValue(Rect rect, object data, GUIStyle style)
    {
        if (data == null)
        {
            return(data);
        }

        Type   type = data.GetType();
        object obj  = data;

        if (type == typeof(int))
        {
            obj = EditorGUI.IntField(rect, (int)data, style);
        }
        else if (type == typeof(short))
        {
            obj = (short)EditorGUI.IntField(rect, (short)data, style);
        }
        else if (type == typeof(long))
        {
            obj = EditorGUI.LongField(rect, (long)data, style);
        }
        else if (type == typeof(double))
        {
            obj = EditorGUI.DoubleField(rect, (double)data, style);
        }
        else if (type == typeof(float))
        {
            obj = EditorGUI.FloatField(rect, (float)data, style);
        }
        else if (type == typeof(bool))
        {
            GUI.Box(rect, "", style);
            obj = EditorGUI.Toggle(rect, (bool)data, "BoldToggle");
        }
        else if (type == typeof(string))
        {
            obj = EditorGUI.TextArea(rect, data.ToString(), style);
        }
        else if (type == typeof(AnimationClip) ||
                 type == typeof(Texture2D) ||
                 type == typeof(Texture) ||
                 type == typeof(Sprite) ||
                 type == typeof(AnimatorController) ||
                 type.BaseType == typeof(UnityEngine.Object) || type.BaseType == typeof(Component) || type.BaseType == typeof(MonoBehaviour))
        {
            GUI.Box(rect, "", style);
            obj = EditorGUI.ObjectField(rect, (UnityEngine.Object)data, type, true);
        }

        else if (type.BaseType == typeof(Enum))
        {
            obj = EditorGUI.EnumPopup(rect, "", (Enum)Enum.Parse(type, data.ToString()), style);
        }
        else if (type == typeof(Vector3))
        {
            GUI.Box(rect, "", style);
            obj = EditorGUI.Vector3Field(rect, "", (Vector3)data);
        }
        else if (type == typeof(Vector2))
        {
            GUI.Box(rect, "", style);
            obj = EditorGUI.Vector2Field(rect, "", (Vector2)data);
        }
        else if (type == typeof(Vector3Int))
        {
            GUI.Box(rect, "", style);
            obj = EditorGUI.Vector3IntField(rect, "", (Vector3Int)data);
        }
        else if (type == typeof(Vector2Int))
        {
            GUI.Box(rect, "", style);
            obj = EditorGUI.Vector2IntField(rect, "", (Vector2Int)data);
        }
        else if (type == typeof(Vector4))
        {
            GUI.Box(rect, "", style);
            obj = EditorGUI.Vector4Field(rect, "", (Vector4)data);
        }
        else if (type == typeof(Color))
        {
            GUI.Box(rect, "", style);
            obj = EditorGUI.ColorField(rect, (Color)data);
        }
        //else if (type.Name == typeof(List<>).Name)
        //{


        //}
        //else if (type.Name == typeof(Dictionary<,>).Name)
        //{

        //}
        //else if (type.IsArray)
        //{

        //}
        //else if ((type.IsClass && type != typeof(string)) || type.IsValueType)
        //{

        //}



        return(obj);
    }
Beispiel #9
0
        /// <summary>
        /// 绘制字段
        /// </summary>
        /// <param name="rect">区域</param>
        /// <param name="type">类型</param>
        /// <param name="value">值</param>
        /// <param name="label">名</param>
        /// <returns></returns>
        public static object DrawField(Rect rect, Type type, object value, GUIContent label)
        {
            if (value == null)
            {
                if (!typeof(UnityObject).IsAssignableFrom(type))
                {
                    value = CreateInstance(type);
                }
            }
            if (!IsSupport(type))
            {
                return(null);
            }
            if (type.IsEnum)
            {
                return(EditorGUI.EnumPopup(rect, label, (Enum)value));
            }
            if (type.Equals(typeof(bool)))
            {
                return(EditorGUI.Toggle(rect, label, value == null ? false : (bool)value));
            }
            if (type.Equals(typeof(short)) || type.Equals(typeof(ushort)) ||
                type.Equals(typeof(int)) || type.Equals(typeof(uint)))
            {
                return(EditorGUI.IntField(rect, label, value == null ? 0 : (int)value));
            }
            if (type.Equals(typeof(long)) || type.Equals(typeof(ulong)))
            {
                return(EditorGUI.LongField(rect, label, value == null ? 0 : (long)value));
            }
            if (type.Equals(typeof(float)))
            {
                return(EditorGUI.FloatField(rect, label, value == null ? 0 : (float)value));
            }
            if (type.Equals(typeof(double)))
            {
                return(EditorGUI.DoubleField(rect, label, value == null ? 0 : (double)value));
            }
            if (type.Equals(typeof(string)))
            {
                return(EditorGUI.TextField(rect, label, value == null ? "" : (string)value));
            }
            if (type.Equals(typeof(Vector2)))
            {
                return(EditorGUI.Vector2Field(rect, label, value == null ? Vector2.zero : (Vector2)value));
            }
            if (type.Equals(typeof(Vector2Int)))
            {
                return(EditorGUI.Vector2IntField(rect, label, value == null ? Vector2Int.zero : (Vector2Int)value));
            }
            if (type.Equals(typeof(Vector3)))
            {
                return(EditorGUI.Vector3Field(rect, label, value == null ? Vector3.zero : (Vector3)value));
            }
            if (type.Equals(typeof(Vector3Int)))
            {
                return(EditorGUI.Vector3IntField(rect, label, value == null ? Vector3Int.zero : (Vector3Int)value));
            }
            if (type.Equals(typeof(Vector4)))
            {
                return(EditorGUI.Vector4Field(rect, label, value == null ? Vector4.zero : (Vector4)value));
            }
            if (type.Equals(typeof(Quaternion)))
            {
                Quaternion quaternion = value == null ? Quaternion.identity : (Quaternion)value;
                Vector4    vector     = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                vector = EditorGUI.Vector4Field(rect, label, vector);
                quaternion.Set(vector.x, vector.y, vector.z, vector.w);
                return(quaternion);
            }
            if (type.Equals(typeof(Color)))
            {
                return(EditorGUI.ColorField(rect, label, value == null ? Color.black : (Color)value));
            }
            if (type.Equals(typeof(Rect)))
            {
                return(EditorGUI.RectField(rect, label, value == null ? Rect.zero : (Rect)value));
            }
            if (type.Equals(typeof(AnimationCurve)))
            {
                return(EditorGUI.CurveField(rect, label, value == null ? AnimationCurve.EaseInOut(0f, 0f, 1f, 1f) : (AnimationCurve)value));
            }
            if (type.Equals(typeof(LayerMask)))
            {
                return((LayerMask)EditorGUI.LayerField(rect, label, (LayerMask)(value == null ? (-1) : value)));
            }
            if (typeof(UnityObject).IsAssignableFrom(type))
            {
                return(EditorGUI.ObjectField(rect, label, (UnityObject)value, type, true));
            }
            if (ObjectDrawer.CheckHasCustomDrawer(type))
            {
                ObjectDrawer objectDrawer = ObjectDrawer.CreateEditor(value);
                return(objectDrawer.OnGUI(rect, label));
            }

            return(null);
        }
Beispiel #10
0
        public override void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor)
        {
            Stack <MaterialProperty> cProps = new Stack <MaterialProperty>();

            for (int i = 0; i < 4; i++)
            {
                if (i == 0)
                {
                    cProps.Push(prop);
                    continue;
                }
                var p = SimpleShaderGUI.FindProp(colorStr[i - 1], props);
                if (p != null && p.type == MaterialProperty.PropType.Color)
                {
                    cProps.Push(p);
                }
            }
            int count = cProps.Count;

            var rect = EditorGUILayout.GetControlRect();

            var p1 = cProps.Pop();

            EditorGUI.showMixedValue = p1.hasMixedValue;
            editor.ColorProperty(rect, p1, label.text);

            for (int i = 1; i < count; i++)
            {
                var cProp = cProps.Pop();
                EditorGUI.showMixedValue = cProp.hasMixedValue;
                Rect  r        = new Rect(rect);
                var   interval = 13 * i * (-0.25f + EditorGUI.indentLevel * 1.25f);
                float w        = propRight * (0.8f + EditorGUI.indentLevel * 0.2f);
                r.xMin += r.width - w * (i + 1) + interval;
                r.xMax -= w * i - interval;

                EditorGUI.BeginChangeCheck();
                Color src, dst;
                if (isHSV)
                {
                    src = Func.HSVToRGB(cProp.colorValue.linear).gamma;
                }
                else
                {
                    src = cProp.colorValue;
                }
                var hdr = (prop.flags & MaterialProperty.PropFlags.HDR) != MaterialProperty.PropFlags.None;
                dst = EditorGUI.ColorField(r, GUIContent.none, src, true, true, hdr);
                if (EditorGUI.EndChangeCheck())
                {
                    if (isHSV)
                    {
                        cProp.colorValue = Func.RGBToHSV(dst.linear).gamma;
                    }
                    else
                    {
                        cProp.colorValue = dst;
                    }
                }
            }
            EditorGUI.showMixedValue = false;
            Func.SetShaderKeyWord(editor.targets, preHSVKeyWord, isHSV);
        }
        private void DrawValueFieldInValueMode(Rect position, SerializedProperty property, VariantReference.EditorHelper helper)
        {
            if (helper.Target == null)
            {
                return;
            }
            var variant = helper.Target;

            if (this.RestrictVariantType && helper._type != this.VariantTypeRestrictedTo)
            {
                helper.PrepareForValueTypeChange(this.VariantTypeRestrictedTo);
                GUI.changed = true; //force change
            }

            var r0 = new Rect(position.xMin, position.yMin, 90.0f, EditorGUIUtility.singleLineHeight);
            var r1 = new Rect(r0.xMax, position.yMin, position.xMax - r0.xMax, EditorGUIUtility.singleLineHeight);

            var cache = SPGUI.DisableIf(this.RestrictVariantType);

            EditorGUI.BeginChangeCheck();
            var valueType = (VariantType)EditorGUI.EnumPopup(r0, GUIContent.none, variant.ValueType);

            if (EditorGUI.EndChangeCheck())
            {
                helper.PrepareForValueTypeChange(valueType);
            }
            cache.Reset();

            if (_typeRestrictedTo.IsEnum)
            {
                variant.IntValue = ConvertUtil.ToInt(EditorGUI.EnumPopup(r1, ConvertUtil.ToEnumOfType(_typeRestrictedTo, variant.IntValue)));
            }
            else
            {
                switch (valueType)
                {
                case VariantType.Null:
                    cache = SPGUI.Disable();
                    EditorGUI.TextField(r1, "Null");
                    cache.Reset();
                    break;

                case VariantType.String:
                    variant.StringValue = EditorGUI.TextField(r1, variant.StringValue);
                    break;

                case VariantType.Boolean:
                    variant.BoolValue = EditorGUI.Toggle(r1, variant.BoolValue);
                    break;

                case VariantType.Integer:
                    variant.IntValue = EditorGUI.IntField(r1, variant.IntValue);
                    break;

                case VariantType.Float:
                    variant.FloatValue = EditorGUI.FloatField(r1, variant.FloatValue);
                    break;

                case VariantType.Double:
                    variant.DoubleValue = ConvertUtil.ToDouble(EditorGUI.TextField(r1, variant.DoubleValue.ToString()));
                    break;

                case VariantType.Vector2:
                    variant.Vector2Value = EditorGUI.Vector2Field(r1, GUIContent.none, variant.Vector2Value);
                    break;

                case VariantType.Vector3:
                    variant.Vector3Value = EditorGUI.Vector3Field(r1, GUIContent.none, variant.Vector3Value);
                    break;

                case VariantType.Vector4:
                    variant.Vector4Value = EditorGUI.Vector4Field(r1, (string)null, variant.Vector4Value);
                    break;

                case VariantType.Quaternion:
                    variant.QuaternionValue = SPEditorGUI.QuaternionField(r1, GUIContent.none, variant.QuaternionValue);
                    break;

                case VariantType.Color:
                    variant.ColorValue = EditorGUI.ColorField(r1, variant.ColorValue);
                    break;

                case VariantType.DateTime:
                    variant.DateValue = ConvertUtil.ToDate(EditorGUI.TextField(r1, variant.DateValue.ToString()));
                    break;

                case VariantType.GameObject:
                    variant.GameObjectValue = EditorGUI.ObjectField(r1, variant.GameObjectValue, typeof(GameObject), true) as GameObject;
                    break;

                case VariantType.Component:
                {
                    _selectComponentDrawer.AllowNonComponents = false;
                    _selectComponentDrawer.RestrictionType    = ComponentUtil.IsAcceptableComponentType(_forcedObjectType) ? _forcedObjectType : typeof(Component);
                    _selectComponentDrawer.ShowXButton        = true;
                    var targProp = property.FindPropertyRelative(PROP_UNITYOBJREF);
                    EditorGUI.BeginChangeCheck();
                    _selectComponentDrawer.OnGUI(r1, targProp);
                    if (EditorGUI.EndChangeCheck())
                    {
                        variant.ComponentValue = targProp.objectReferenceValue as Component;
                    }
                }
                break;

                case VariantType.Object:
                {
                    var obj = variant.ObjectValue;
                    if (ComponentUtil.IsAcceptableComponentType(_forcedObjectType))
                    {
                        if (obj is GameObject || obj is Component)
                        {
                            _selectComponentDrawer.AllowNonComponents = false;
                            _selectComponentDrawer.RestrictionType    = _forcedObjectType;
                            _selectComponentDrawer.ShowXButton        = true;
                            var targProp = property.FindPropertyRelative(PROP_UNITYOBJREF);
                            EditorGUI.BeginChangeCheck();
                            _selectComponentDrawer.OnGUI(r1, targProp);
                            if (EditorGUI.EndChangeCheck())
                            {
                                variant.ObjectValue = targProp.objectReferenceValue as Component;
                            }
                        }
                        else
                        {
                            EditorGUI.BeginChangeCheck();
                            obj = EditorGUI.ObjectField(r1, obj, typeof(UnityEngine.Object), true);
                            if (EditorGUI.EndChangeCheck())
                            {
                                if (obj == null)
                                {
                                    variant.ObjectValue = null;
                                }
                                else if (TypeUtil.IsType(obj.GetType(), _forcedObjectType))
                                {
                                    variant.ObjectValue = obj;
                                }
                                else
                                {
                                    var go = GameObjectUtil.GetGameObjectFromSource(obj);
                                    if (go != null)
                                    {
                                        variant.ObjectValue = go.GetComponent(_forcedObjectType);
                                    }
                                    else
                                    {
                                        variant.ObjectValue = null;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        variant.ObjectValue = EditorGUI.ObjectField(r1, obj, _forcedObjectType, true);
                    }
                }
                break;

                case VariantType.LayerMask:
                {
                    variant.LayerMaskValue = SPEditorGUI.LayerMaskField(r1, GUIContent.none, (int)variant.LayerMaskValue);
                }
                break;

                case VariantType.Rect:
                {
                    variant.RectValue = EditorGUI.RectField(r1, variant.RectValue);
                }
                break;
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            using (var propScope = Disposables.PropertyScope(position, label, property)) {
                label = propScope.content;
                var rect = position;
                rect.height = SingleLine;
                rect.y     += 1;
                var colour = GetTargetObject(property);

                if (colour == null)
                {
                    return;
                }

                var rect2 = rect;
                rect2.width         = IndentSize;
                property.isExpanded = EditorGUI.Foldout(rect2, property.isExpanded, "");
                rect2 = rect;

                using (var ChangeCheck = Disposables.ChangeCheck()) {
                    var col = EditorGUI.ColorField(rect2, new GUIContent(property.displayName, property.displayName), colour);
                    colour.SetColor(col);

                    if (!property.isExpanded)
                    {
                        return;
                    }

                    using (Disposables.Indent()) {
                        rect.y += 1 + SingleLine;
                        var A = EditorGUI.IntField(rect, new GUIContent("Alpha", "Alpha"), colour.A);
                        rect.y += 1 + SingleLine;
                        var R = EditorGUI.IntField(rect, new GUIContent("Red", "Red"), colour.R);
                        rect.y += 1 + SingleLine;
                        var G = EditorGUI.IntField(rect, new GUIContent("Green", "Green"), colour.G);
                        rect.y += 1 + SingleLine;
                        var B = EditorGUI.IntField(rect, new GUIContent("Blue", "Blue"), colour.B);
                        rect.y += 1 + SingleLine;

                        if (GUI.Button(rect, new GUIContent("Randomize Colour", "Randomizes the Colour")))
                        {
                            var colHSV = Random.ColorHSV();
                            colour.SetColor(colHSV);

                            return;
                        }

                        if (A >= 255)
                        {
                            colour.A = 255;
                        }
                        else if (A <= 0)
                        {
                            colour.A = 0;
                        }
                        else
                        {
                            colour.A = (byte)A;
                        }

                        if (R >= 255)
                        {
                            colour.R = 255;
                        }
                        else if (R <= 0)
                        {
                            colour.R = 0;
                        }
                        else
                        {
                            colour.R = (byte)R;
                        }

                        if (G >= 255)
                        {
                            colour.G = 255;
                        }
                        else if (G <= 0)
                        {
                            colour.G = 0;
                        }
                        else
                        {
                            colour.G = (byte)G;
                        }

                        if (B >= 255)
                        {
                            colour.B = 255;
                        }
                        else if (B <= 0)
                        {
                            colour.B = 0;
                        }
                        else
                        {
                            colour.B = (byte)B;
                        }

                        if (ChangeCheck.changed)
                        {
                            Undo.RecordObject(property.serializedObject.targetObject, "ColourChange");
                        }
                    }
                }
            }
        }
Beispiel #13
0
    public static bool SinglePropertyField(Rect position, SerializedProperty property, GUIContent label)
    {
        //PropertyDrawer drawer = PropertyDrawer.GetDrawer(property);
        //if (drawer != null)
        //{
        //    EditorLook look = EditorGUIUtility.look;
        //    float labelWidth = EditorGUIUtility.labelWidth;
        //    float fieldWidth = EditorGUI.kNumberW;
        //    drawer.OnGUI(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
        //    if (EditorGUIUtility.look != look)
        //    {
        //        if (look == EditorLook.LikeControls)
        //        {
        //            EditorGUIUtility.LookLikeControls(labelWidth, fieldWidth);
        //        }
        //        else
        //        {
        //            EditorGUIUtility.LookLikeInspector();
        //        }
        //    }
        //    EditorGUIUtility.labelWidth = labelWidth;
        //    EditorGUI.kNumberW = fieldWidth;
        //    return false;
        //}
        label = EditorGUI.BeginProperty(position, label, property);
        SerializedPropertyType propertyType = property.propertyType;
        bool flag = false;

        if (!HasVisibleChildFields(property))
        {
            switch (propertyType)
            {
            case SerializedPropertyType.Integer:
            {
                EditorGUI.BeginChangeCheck();
                int intValue = EditorGUI.IntField(position, label, property.intValue);
                if (EditorGUI.EndChangeCheck())
                {
                    property.intValue = intValue;
                }
                goto IL_326;
            }

            case SerializedPropertyType.Boolean:
            {
                EditorGUI.BeginChangeCheck();
                bool boolValue = EditorGUI.Toggle(position, label, property.boolValue);
                if (EditorGUI.EndChangeCheck())
                {
                    property.boolValue = boolValue;
                }
                goto IL_326;
            }

            case SerializedPropertyType.Float:
            {
                EditorGUI.BeginChangeCheck();
                float floatValue = EditorGUI.FloatField(position, label, property.floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    property.floatValue = floatValue;
                }
                goto IL_326;
            }

            case SerializedPropertyType.String:
            {
                EditorGUI.BeginChangeCheck();
                string stringValue = EditorGUI.TextField(position, label, property.stringValue);
                if (EditorGUI.EndChangeCheck())
                {
                    property.stringValue = stringValue;
                }
                goto IL_326;
            }

            case SerializedPropertyType.Color:
            {
                EditorGUI.BeginChangeCheck();
                Color colorValue = EditorGUI.ColorField(position, label, property.colorValue);
                if (EditorGUI.EndChangeCheck())
                {
                    property.colorValue = colorValue;
                }
                goto IL_326;
            }

            case SerializedPropertyType.ObjectReference:
                ObjectReferenceField(position, property, label);
                goto IL_326;

            case SerializedPropertyType.LayerMask:
                LayerMaskField(position, property, label);
                goto IL_326;

            case SerializedPropertyType.Enum:
                Popup(position, property, label);
                goto IL_326;

            case SerializedPropertyType.Vector3:
                Vector3Field(position, property, label);
                goto IL_326;

            case SerializedPropertyType.Rect:
                RectField(position, property, label);
                goto IL_326;

            case SerializedPropertyType.ArraySize:
            {
                EditorGUI.BeginChangeCheck();
                int intValue2 = ArraySizeField(position, label, property.intValue, EditorStyles.numberField);
                if (EditorGUI.EndChangeCheck())
                {
                    property.intValue = intValue2;
                }
                goto IL_326;
            }

            case SerializedPropertyType.Character:
            {
                char[] value = new char[]
                {
                    (char)property.intValue
                };
                bool changed = GUI.changed;
                GUI.changed = false;
                string text = EditorGUI.TextField(position, label, new string(value));
                if (GUI.changed)
                {
                    if (text.Length == 1)
                    {
                        property.intValue = (int)text[0];
                    }
                    else
                    {
                        GUI.changed = false;
                    }
                }
                GUI.changed |= changed;
                goto IL_326;
            }

            case SerializedPropertyType.AnimationCurve:
            {
                int controlID = GetControlID(s_CurveHash, EditorGUIUtility.native, position);
                DoCurveField(EditorGUI.PrefixLabel(position, controlID, label), controlID, null, kCurveColor, default(Rect), property);
                goto IL_326;
            }

            case SerializedPropertyType.Bounds:
                BoundsField(position, property, label);
                goto IL_326;

            case SerializedPropertyType.Gradient:
            {
                int controlID2 = GetControlID(s_CurveHash, EditorGUIUtility.native, position);
                DoGradientField(EditorGUI.PrefixLabel(position, controlID2, label), controlID2, null, property);
                goto IL_326;
            }
            }
            int controlID3 = GetControlID(s_GenericField, FocusType.Keyboard, position);
            EditorGUI.PrefixLabel(position, controlID3, label);
            IL_326 :;
        }
        else
        {
            int       controlID4 = GetControlID(s_FoldoutHash, FocusType.Passive, position);
            EventType type       = Event.current.type;
            if (type != EventType.DragUpdated && type != EventType.DragPerform)
            {
                if (type == EventType.DragExited)
                {
                    if (GUI.enabled)
                    {
                        HandleUtility.Repaint();
                    }
                }
            }
            else
            {
                if (position.Contains(Event.current.mousePosition) && GUI.enabled)
                {
                    Object[] objectReferences = DragAndDrop.objectReferences;
                    Object[] array            = new Object[1];
                    bool     flag2            = false;
                    Object[] array2           = objectReferences;
                    for (int i = 0; i < array2.Length; i++)
                    {
                        Object @object = array2[i];
                        array[0] = @object;
                        Object object2 = ValidateObjectFieldAssignment(array, null, property);
                        if (object2 != null)
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                            if (Event.current.type == EventType.DragPerform)
                            {
                                property.AppendFoldoutPPtrValue(object2);
                                flag2 = true;
                                DragAndDrop.activeControlID = 0;
                            }
                            else
                            {
                                DragAndDrop.activeControlID = controlID4;
                            }
                        }
                    }
                    if (flag2)
                    {
                        GUI.changed = true;
                        DragAndDrop.AcceptDrag();
                        Event.current.Use();
                    }
                }
            }
            flag = property.isExpanded;
            if (lookLikeInspector)
            {
                int num = EditorStyles.foldout.padding.left - EditorStyles.label.padding.left;
                position.x     -= (float)num;
                position.width += (float)num;
            }
            GUI.enabled &= property.editable;
            GUIStyle style = (DragAndDrop.activeControlID != -10) ? EditorStyles.foldout : EditorStyles.foldoutPreDrop;
            bool     flag3 = EditorGUI.Foldout(position, flag, s_PropertyFieldTempContent, true, style);
            if (flag3 != flag)
            {
                if (Event.current.alt)
                {
                    SetExpandedRecurse(property, flag3);
                }
                else
                {
                    property.isExpanded = flag3;
                }
            }
            flag = flag3;
        }
        EditorGUI.EndProperty();
        if (Event.current.type == EventType.ExecuteCommand || Event.current.type == EventType.ValidateCommand)
        {
            if (GUIUtility.keyboardControl == lastControlID && (Event.current.commandName == "Delete" || Event.current.commandName == "SoftDelete"))
            {
                if (Event.current.type == EventType.ExecuteCommand)
                {
                    property.DeleteCommand();
                }
                Event.current.Use();
            }
            if (GUIUtility.keyboardControl == lastControlID && Event.current.commandName == "Duplicate")
            {
                if (Event.current.type == EventType.ExecuteCommand)
                {
                    property.DuplicateCommand();
                }
                Event.current.Use();
            }
        }
        return(flag);
    }
Beispiel #14
0
    override public void OnInspectorGUI()
    {
        GA_HeatMapRenderer render = target as GA_HeatMapRenderer;


        if (render == null || render.Histogram == null)
        {
            return;
        }

        if (!EditorUtility.IsPersistent(target))
        {
            PrefabUtility.DisconnectPrefabInstance(render.gameObject);
        }

        EditorGUIUtility.LookLikeControls();
        EditorGUI.indentLevel = 1;


        EditorGUILayout.Space();

        if (render.transform.position != Vector3.zero)
        {
            // not placed in zero and heatmap data is off. It might be useful to move the heatmap to create layers, but we should warn the user.
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Heatmap is not in (0,0,0) - the visualization will be offset!");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Reset position"))
            {
                render.transform.position = Vector3.zero;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Histogram of dataset", EditorStyles.largeLabel);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Shows the data point count for event occurrences in the dataset", EditorStyles.miniLabel);
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();


        GUILayout.Box("", GUIStyle.none, GUILayout.Width(20));      //layout hack
        GUILayout.Box("", GUILayout.MinWidth(50), GUILayout.MaxWidth(700), GUILayout.MinHeight(200));
        if (Event.current.type == EventType.Repaint)
        {
            lastrect = GUILayoutUtility.GetLastRect();
        }

        GUILayout.Box("", GUIStyle.none, GUILayout.Width(15));      //layout hack to get right margin

        if (render.Histogram != null && (render.Histogram.Data == null || render.Histogram.Data.Length == 0))
        {
            GUI.Label(new Rect(lastrect.x + lastrect.width / 2 - 50, lastrect.y + lastrect.height / 2, 100, 40), "No data loaded", EditorStyles.largeLabel);
        }
        else if (render.Histogram != null && render.Histogram.Data != null && render.Histogram.Data.Length < 3)
        {
            GUI.Label(new Rect(lastrect.x + lastrect.width / 2 - 105, lastrect.y + lastrect.height / 2, 300, 40), "Not enough data to show histogram", EditorStyles.largeLabel);
        }

        Vector2 textPos    = new Vector2(lastrect.xMin + lastrect.height / 2 - 63, lastrect.yMax - 20);
        Vector2 textGuiPos = EditorGUIUtility.GUIToScreenPoint(textPos);

        GUIUtility.RotateAroundPivot(-90f, new Vector2(lastrect.xMin, lastrect.yMax));
        if (textGuiPos.y > 125)
        {
            int maxChars = ((int)textGuiPos.y - 125) / 5;
            GUI.Label(new Rect(textPos.x, textPos.y, 200, 20), "Number of data points".Substring(0, Mathf.Max(0, Mathf.Min(maxChars, 21))), EditorStyles.label);
        }
        GUIUtility.RotateAroundPivot(90f, new Vector2(lastrect.xMin, lastrect.yMax));
        GUI.Label(new Rect(lastrect.xMin + lastrect.width / 2 - 85, lastrect.yMax + 40, 200, 20), "Frequency / event occurrences", EditorStyles.label);

        if (render.Histogram.Data != null && render.Histogram.Data.Length >= 3)
        {
            float margin = lastrect.width / (render.Histogram.Data.Length);

            int numLabels     = 10;
            int labelInterval = Mathf.FloorToInt(render.Histogram.Data.Length / (float)numLabels);
            labelInterval = Mathf.Max(1, labelInterval);

            for (int i = 0; i < render.Histogram.Data.Length; i++)
            {
                float lineWidth = Mathf.Max(2, margin - 2);

                if (Screen.width > 90 + i * lineWidth)
                {
                    float c   = render.Histogram.Data[i] * lastrect.height;
                    float x   = lastrect.x + (i + 0.5f) * margin;
                    float y   = lastrect.y + lastrect.height;
                    float pct = i / (float)render.Histogram.Data.Length;

                    Color nonSelectedColor = new Color(0.6f, 0.6f, 0.6f, 0.3f);

                    float rangePct = (pct - render.RangeMin) / (render.RangeMax - render.RangeMin);

                    float line, linePct, colorPct, barHeight;
                    Color color = Color.white;
                    for (int xline = 0; xline < lineWidth; xline++)
                    {
                        Vector2 guiPos = EditorGUIUtility.GUIToScreenPoint(new Vector2(x, y));
                        barHeight = Mathf.Min(c, guiPos.y - 93);                         //cut bar height if too high for inspector window
                        barHeight = Mathf.Max(0f, barHeight);
                        line      = x - lineWidth / 2 + xline;
                        linePct   = pct + 1f / render.Histogram.Data.Length * (xline / lineWidth);

                        if (render.Histogram.RealDataMin >= 0)
                        {
                            colorPct = rangePct + 1f / render.Histogram.Data.Length * (xline / lineWidth);
                            color    = Color.Lerp(render.MinColor, render.MaxColor, colorPct);
                        }
                        else
                        {
                            float zeroNorm = (0 - render.Histogram.RealDataMin) / (render.Histogram.RealDataMax - render.Histogram.RealDataMin);
                            if (pct >= zeroNorm * 0.9f && pct <= zeroNorm * 1.1f)
                            {
                                color = Color.white;
                            }
                            else if (pct < zeroNorm)
                            {
                                float newNorm = pct / zeroNorm * (1 - render.RangeMin / zeroNorm);
                                color = Color.Lerp(render.MinColor, Color.white, newNorm);
                            }
                            else
                            {
                                float newNorm = zeroNorm / pct * render.RangeMax;
                                color = Color.Lerp(Color.white, render.MaxColor, 1 - newNorm);
                            }
                        }

                        if (linePct <= render.RangeMin || linePct >= render.RangeMax)
                        {
                            color = nonSelectedColor;
                        }

                        GA_GUIHelper.DrawLine(new Vector2(line, y), new Vector2(line, y - barHeight), color);
                    }
                }
            }
        }


        /// 0% label
        Vector2 label = new Vector2(lastrect.xMin, lastrect.yMax + 10);

        GUIUtility.RotateAroundPivot(50f, label);
        GUI.Label(new Rect(label.x, label.y, 40, 20), "0%", EditorStyles.miniLabel);
        GUIUtility.RotateAroundPivot(-50f, label);
        // 50% label
        label = new Vector2(lastrect.center.x, lastrect.yMax + 10);
        GUIUtility.RotateAroundPivot(50f, label);
        GUI.Label(new Rect(label.x, label.y, 40, 20), "50%", EditorStyles.miniLabel);
        GUIUtility.RotateAroundPivot(-50f, label);

        // 100% label
        label = new Vector2(lastrect.xMax - 14, lastrect.yMax + 10);
        GUIUtility.RotateAroundPivot(50f, label);
        GUI.Label(new Rect(label.x, label.y, 40, 20), "100%", EditorStyles.miniLabel);
        GUIUtility.RotateAroundPivot(-50f, label);

        // 100% label. real value
        label = new Vector2(lastrect.xMax - (10 + Mathf.Pow(render.Histogram.RealDataMax, 0.25f)), lastrect.yMin - 15);

        GUI.Label(new Rect(label.x, label.y, 75, 20), render.Histogram.RealDataMax.ToString("G5"), EditorStyles.miniLabel);

        // 0% label. real value
        label = new Vector2(lastrect.xMin, lastrect.yMin - 15);
        GUI.Label(new Rect(label.x, label.y, 75, 20), render.Histogram.RealDataMin.ToString("G5"), EditorStyles.miniLabel);

        /*if (render.Histogram.RealDataMin < 0)
         * {
         *      // if minimum count is below zero then also show zero real value point
         *      float zeroNorm = (0 - render.Histogram.RealDataMin) / (render.Histogram.RealDataMax - render.Histogram.RealDataMin);
         *      label = new Vector2((zeroNorm * lastrect.xMax),lastrect.yMin-15);
         *      GUI.Label(new Rect(label.x,label.y,75,20),"0",EditorStyles.miniLabel);
         * }*/

        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Box("", GUIStyle.none, GUILayout.Width(8));      //layout hack
        EditorGUILayout.MinMaxSlider(ref render.RangeMin, ref render.RangeMax, 0f, 1f, GUILayout.Width(lastrect.width + 15));

        GUILayout.EndHorizontal();


        render.MinColor = EditorGUI.ColorField(new Rect(lastrect.xMin - 10, lastrect.yMax + 44, 50, 18), render.MinColor);
        render.MaxColor = EditorGUI.ColorField(new Rect(lastrect.xMax - 45, lastrect.yMax + 44, 50, 18), render.MaxColor);

        GUILayout.BeginHorizontal();
        GUILayout.Box("", GUIStyle.none, GUILayout.Height(70));      //layout hack
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Show heatmap:");
        if (render.BillBoard != null)
        {
            render.BillBoard.GetComponent <MeshRenderer>().enabled = EditorGUILayout.Toggle(render.BillBoard.GetComponent <MeshRenderer>().enabled);
        }
        else
        {
            EditorGUILayout.Toggle(true);
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Preset Colors:", GUILayout.Width(155));
        if (GUILayout.Button("Select Color Preset"))
        {
            GA_HeatmapColorPresetPicker colorpresetpicker = ScriptableObject.CreateInstance <GA_HeatmapColorPresetPicker>();
            colorpresetpicker.ShowUtility();
            Vector2 pos = EditorGUIUtility.GUIToScreenPoint(new Vector2(GUILayoutUtility.GetLastRect().x + 150, Event.current.mousePosition.y - 25));
            colorpresetpicker.position  = new Rect(pos.x, pos.y, 180, 145);
            colorpresetpicker.OnPicked += HandleColorPresetPicker;
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Histogram scale:");
        GA_Histogram.HistogramScale oldScale = render.HistogramScale;

        render.HistogramScale = (GA_Histogram.HistogramScale)EditorGUILayout.EnumPopup(render.HistogramScale);

        if (render.HistogramScale != oldScale)
        {
            render.OnScaleChanged();
        }

        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();

        EditorGUILayout.PrefixLabel("Render model:");
        GA_HeatMapRenderer.RenderModel oldRenderModel = render.CurrentRenderModel;
        render.CurrentRenderModel = (GA_HeatMapRenderer.RenderModel)EditorGUILayout.EnumPopup(render.CurrentRenderModel);
        if (render.CurrentRenderModel != oldRenderModel)
        {
            render.RenderModelChanged();
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Point radius:");

        float oldMaxRadius = render.MaxRadius;

        render.MaxRadius = EditorGUILayout.Slider(render.MaxRadius, 0f, 10f);
        if (render.MaxRadius != oldMaxRadius)
        {
            render.SetMaterialVariables();
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Show values (slow):");
        render.ShowValueLabels = EditorGUILayout.Toggle(render.ShowValueLabels);
        GUILayout.EndHorizontal();

        EditorGUILayout.Space();

        if (GUI.changed)
        {
            if (SystemInfo.graphicsShaderLevel < 20)
            {
                GA.Log("GameAnalytics: GPU does not support shader needed");
            }

            EditorUtility.SetDirty(target);
            render.SetMaterialVariables();
        }
    }
Beispiel #15
0
    // Draw the settings toolbar
    // Return true if image rects need to be updated.
    public static bool DrawToolbar(Rect window)
    {
        bool updateRects = false;

        // Draw toolbar bg
        EditorGUI.DrawRect(new Rect(0, 0, window.width, 40), toolbarColor);

        if (GUI.Button(new Rect(5, 4, 50, 30), "New"))
        {
            UPAImageCreationWindow.Init();
        }
        if (GUI.Button(new Rect(60, 4, 50, 30), "Open"))
        {
            CurrentImg = UPASession.OpenImage();
            if (CurrentImg == null)
            {
                return(false);
            }
        }
        if (GUI.Button(new Rect(115, 4, 50, 30), "Export"))
        {
            UPAExportWindow.Init(CurrentImg);
        }

        if (GUI.Button(new Rect(179, 6, 25, 25), "+"))
        {
            CurrentImg.gridSpacing *= 1.5f;
            updateRects             = true;
        }
        if (GUI.Button(new Rect(209, 6, 25, 25), "-"))
        {
            CurrentImg.gridSpacing *= 0.5f;
            updateRects             = true;
        }

        CurrentImg.selectedColor = EditorGUI.ColorField(new Rect(250, 7, 70, 25), CurrentImg.selectedColor);
        EditorGUI.DrawRect(new Rect(303, 7, 20, 25), toolbarColor);
        //bgColor = EditorGUI.ColorField (new Rect (400, 4, 70, 25), bgColor);

        GUI.backgroundColor = Color.white;
        if (CurrentImg.tool == UPATool.PaintBrush)
        {
            GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f);
        }
        if (GUI.Button(new Rect(320, 4, 60, 30), "Paint"))
        {
            CurrentImg.tool = UPATool.PaintBrush;
        }
        GUI.backgroundColor = Color.white;
        if (CurrentImg.tool == UPATool.BoxBrush)
        {
            GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f);
        }
        if (GUI.Button(new Rect(450, 4, 60, 30), "Box Fill"))
        {
            EditorUtility.DisplayDialog(
                "In Development",
                "This feature is currently being developed.",
                "Get it done please");
            //tool = UPATool.BoxBrush;
        }
        GUI.backgroundColor = Color.white;
        if (CurrentImg.tool == UPATool.Eraser)
        {
            GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f);
        }
        if (GUI.Button(new Rect(385, 4, 60, 30), "Erase"))
        {
            CurrentImg.tool = UPATool.Eraser;
        }
        GUI.backgroundColor = Color.white;

        style.normal.textColor = new Color(0.7f, 0.7f, 0.7f);
        GUI.Label(new Rect(525, 11, 150, 30), "Use WASD to navigate.", style);

        if (GUI.Button(new Rect(670, 4, 80, 30), "Center View"))
        {
            CurrentImg.gridOffsetX = 0;
            CurrentImg.gridOffsetY = 0;
        }

        CurrentImg.gridBGIndex = GUI.Toolbar(new Rect(760, 4, 90, 30), CurrentImg.gridBGIndex, gridBGStrings);

        if (CurrentImg.gridBGIndex == 0)
        {
            gridBGColor = Color.black;
        }
        else
        {
            gridBGColor = Color.white;
        }

        return(updateRects);
    }
    public override void OnInspectorGUI()
    {
        //bool isPro = true;
        //bool showErrors = false;
        //bool showUnderwater = false;
        Color colorEnabled  = new Color(1.0f, 1.0f, 1.0f, 1.0f);
        Color colorDisabled = new Color(1.0f, 1.0f, 1.0f, 0.25f);
        //Color colorWarning = new Color(0.9f,0.5f,0.1f,1.0f);
        Texture logoTexb;
        Texture divTex;
        //Texture divRevTex;
        //Texture divVertTex;
        Texture divHorizTex;

        //bool showCaustic = false;
        int verAdd = 0;

        Suimono.Core.SuimonoModule script = (Suimono.Core.SuimonoModule)target;

        Undo.RecordObject(target, "Changed Area Of Effect");

        //load textures
        logoTexb = Resources.Load("textures/gui_tex_suimonologob_i") as Texture;
        divTex   = Resources.Load("textures/gui_tex_suimonodiv_i") as Texture;
        //divRevTex = Resources.Load("textures/gui_tex_suimonodivrev") as Texture;
        //divVertTex = Resources.Load("textures/gui_tex_suimono_divvert") as Texture;
        divHorizTex = Resources.Load("textures/gui_tex_suimono_divhorz") as Texture;



        if (EditorGUIUtility.isProSkin == true)
        {
            divTex   = Resources.Load("textures/gui_tex_suimonodiv") as Texture;
            logoTexb = Resources.Load("textures/gui_tex_suimonologob") as Texture;
        }



        //int setWidth = Screen.width-220;
        //if (setWidth < 120) setWidth = 120;

        //SET SCREEN WIDTH
        int setWidth = (int)EditorGUIUtility.currentViewWidth - 220;

        if (setWidth < 120)
        {
            setWidth = 120;
        }


        //SUIMONO LOGO
        GUIContent buttonText  = new GUIContent("");
        GUIStyle   buttonStyle = GUIStyle.none;
        Rect       rt          = GUILayoutUtility.GetRect(buttonText, buttonStyle);
        int        margin      = 15;


        //start menu
        GUI.contentColor = new Color(1.0f, 1.0f, 1.0f, 0.4f);
        EditorGUI.LabelField(new Rect(rt.x + margin + 2, rt.y + 37, 50, 18), "Version");
        GUI.contentColor = new Color(1.0f, 1.0f, 1.0f, 0.6f);

        Rect linkVerRect = new Rect(rt.x + margin + 51, rt.y + 37, 90, 18);

        EditorGUI.LabelField(linkVerRect, script.suimonoVersionNumber);
        //if (Event.current.type == EventType.MouseUp && linkVerRect.Contains(Event.current.mousePosition)) Application.OpenURL("http://www.tanukidigital.com/suimono/");

        GUI.contentColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
        GUI.contentColor = new Color(1.0f, 1.0f, 1.0f, 0.4f);
        Rect linkHelpRect = new Rect(rt.x + margin + 165, rt.y + 37, 28, 18);
        Rect linkBugRect  = new Rect(rt.x + margin + 165 + 42, rt.y + 37, 65, 18);
        Rect linkURLRect  = new Rect(rt.x + margin + 165 + 120, rt.y + 37, 100, 18);

        if (Event.current.type == EventType.MouseUp && linkHelpRect.Contains(Event.current.mousePosition))
        {
            Application.OpenURL("http://www.tanukidigital.com/forum/");
        }
        if (Event.current.type == EventType.MouseUp && linkBugRect.Contains(Event.current.mousePosition))
        {
            Application.OpenURL("http://www.tanukidigital.com/forum/");
        }
        if (Event.current.type == EventType.MouseUp && linkURLRect.Contains(Event.current.mousePosition))
        {
            Application.OpenURL("http://www.tanukidigital.com/suimono/");
        }

        EditorGUI.LabelField(new Rect(rt.x + margin + 165 + 30, rt.y + 37, 220, 18), "|");
        EditorGUI.LabelField(new Rect(rt.x + margin + 165 + 110, rt.y + 37, 220, 18), "|");

        GUI.contentColor = new Color(1.0f, 1.0f, 1.0f, 0.4f);
        EditorGUI.LabelField(linkHelpRect, "help");
        EditorGUI.LabelField(linkBugRect, "report bug");
        EditorGUI.LabelField(linkURLRect, "tanukidigital.com");
        // end menu

        GUI.contentColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);


        EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 36), logoTexb);
        GUILayout.Space(40.0f);


        rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
        EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 24), divTex);


        verAdd           = 0;
        GUI.contentColor = colorEnabled;
        GUI.Label(new Rect(rt.x + margin + 10, rt.y + 5, 300, 20), new GUIContent("CONFIGURATION"));


        EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 25, 180, 18), "Camera Mode");
        script.cameraTypeIndex = EditorGUI.Popup(new Rect(rt.x + margin + 165, rt.y + 25, 150, 18), "", script.cameraTypeIndex, script.cameraTypeOptions.ToArray());
        if (script.cameraTypeIndex == 0)
        {
            GUI.contentColor    = colorDisabled;
            GUI.backgroundColor = colorDisabled;
        }

        EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + verAdd + 45, 140, 18), "Scene Camera Object");
        script.manualCamera = EditorGUI.ObjectField(new Rect(rt.x + margin + 165, rt.y + verAdd + 45, setWidth, 18), "", script.manualCamera, typeof(Transform), true) as Transform;

        GUI.contentColor    = colorEnabled;
        GUI.backgroundColor = colorEnabled;
        EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + verAdd + 75, 140, 18), "Scene Track Object");
        script.setTrack = EditorGUI.ObjectField(new Rect(rt.x + margin + 165, rt.y + verAdd + 75, setWidth, 18), "", script.setTrack, typeof(Transform), true) as Transform;
        EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + verAdd + 95, 140, 18), "Scene Light Object");
        script.setLight = EditorGUI.ObjectField(new Rect(rt.x + margin + 165, rt.y + verAdd + 95, setWidth, 18), "", script.setLight, typeof(Light), true) as Light;

        EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + verAdd + 120, 140, 18), "Set Automatic Layers");
        script.autoSetLayers = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + verAdd + 120, 140, 18), "", script.autoSetLayers);

        EditorGUI.LabelField(new Rect(rt.x + margin + 220, rt.y + verAdd + 120, 140, 18), "Set Automatic FX");
        script.autoSetCameraFX = EditorGUI.Toggle(new Rect(rt.x + margin + 200, rt.y + verAdd + 120, 140, 18), "", script.autoSetCameraFX);

        GUILayout.Space(130.0f + verAdd);



        rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
        EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 407, 24), divTex);
        script.showGeneral = EditorGUI.Foldout(new Rect(rt.x + margin + 3, rt.y + 5, 10, 20), script.showGeneral, "");
        GUI.Label(new Rect(rt.x + margin + 10, rt.y + 5, 300, 20), new GUIContent("GENERAL SETTINGS"));

        GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0.0f);
        if (GUI.Button(new Rect(rt.x + margin + 10, rt.y + 5, 370, 20), ""))
        {
            script.showGeneral = !script.showGeneral;
        }
        GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 1.0f);

        if (script.showGeneral)
        {
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 30, 140, 18), "Enable Sounds");
            script.playSounds = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 30, setWidth, 18), "", script.playSounds);
            if (!script.playSounds)
            {
                GUI.contentColor    = colorDisabled;
                GUI.backgroundColor = colorDisabled;
            }
            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 50, 140, 18), "Max Sound Volume");
            script.maxVolume    = EditorGUI.Slider(new Rect(rt.x + margin + 165, rt.y + 50, setWidth, 18), "", script.maxVolume, 0.0f, 1.0f);
            GUI.contentColor    = colorEnabled;
            GUI.backgroundColor = colorEnabled;

            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 70, 160, 18), "Enable Underwater Sound");
            script.playSoundBelow = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 70, 20, 18), "", script.playSoundBelow);
            EditorGUI.LabelField(new Rect(rt.x + margin + 220, rt.y + 70, 160, 18), "Enable Above-Water Sound");
            script.playSoundAbove = EditorGUI.Toggle(new Rect(rt.x + margin + 200, rt.y + 70, 20, 18), "", script.playSoundAbove);

            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin + 10, rt.y + 95, 372, 1), divHorizTex);

            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 100, 140, 18), "Enable Underwater FX");
            script.enableUnderwaterFX = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 100, 130, 18), "", script.enableUnderwaterFX);
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 120, 140, 18), "Enable Transition FX");
            script.enableTransition = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 120, 130, 18), "", script.enableTransition);

            script.transitionStrength = EditorGUI.Slider(new Rect(rt.x + margin + 170, rt.y + 120, 200, 18), "", script.transitionStrength, 0.0f, 2.0f);



            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 140, 110, 18), "Enable Interaction");
            script.enableInteraction = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 140, 130, 18), "", script.enableInteraction);

            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 160, 380, 18), "Disable MSAA (fixes display errors in Forward Rendering)");
            script.disableMSAA = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 160, 130, 18), "", script.disableMSAA);

            EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 180, 380, 18), "Underwater Transition Threshold");
            script.underwaterThreshold = EditorGUI.FloatField(new Rect(rt.x + margin + 210, rt.y + 180, 50, 18), "", script.underwaterThreshold);



            GUILayout.Space(180.0f);
        }
        GUILayout.Space(10.0f);



        rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
        EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 24), divTex);
        script.showPerformance = EditorGUI.Foldout(new Rect(rt.x + margin + 3, rt.y + 5, 10, 20), script.showPerformance, "");
        GUI.Label(new Rect(rt.x + margin + 10, rt.y + 5, 300, 20), new GUIContent("ADVANCED WATER SETTINGS"));

        GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0.0f);
        if (GUI.Button(new Rect(rt.x + margin + 10, rt.y + 5, 370, 20), ""))
        {
            script.showPerformance = !script.showPerformance;
        }
        GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 1.0f);


        if (script.showPerformance)
        {
            GUI.contentColor          = colorEnabled;
            GUI.backgroundColor       = colorEnabled;
            script.enableTransparency = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 30, 20, 18), "", script.enableTransparency);
            if (!script.enableTransparency)
            {
                GUI.contentColor    = colorDisabled;
                GUI.backgroundColor = colorDisabled;
            }
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 30, 160, 18), "WATER TRANSPARENCY");

            if (!script.enableTransparency)
            {
                GUI.contentColor    = colorDisabled;
                GUI.backgroundColor = colorDisabled;
            }
            EditorGUI.LabelField(new Rect(rt.x + margin + 230, rt.y + 47, 180, 18), "Render Layers");
            if (script.gameObject.activeInHierarchy)
            {
                script.transLayer = EditorGUI.MaskField(new Rect(rt.x + margin + 230, rt.y + 67, 150, 18), "", script.transLayer, script.suiLayerMasks.ToArray());
            }
            EditorGUI.LabelField(new Rect(rt.x + margin + 110, rt.y + 47, 180, 18), "Use Resolution");
            if (script.gameObject.activeInHierarchy)
            {
                script.transResolution = EditorGUI.Popup(new Rect(rt.x + margin + 110, rt.y + 67, 100, 18), "", script.transResolution, script.resOptions.ToArray());
            }
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 47, 100, 18), "Distance");
            script.transRenderDistance = EditorGUI.FloatField(new Rect(rt.x + margin + 30, rt.y + 67, 60, 18), "", script.transRenderDistance);



            GUI.contentColor    = colorEnabled;
            GUI.backgroundColor = colorEnabled;
            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin + 10, rt.y + 95, 372, 1), divHorizTex);
            script.enableReflections = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 103, 20, 18), "", script.enableReflections);
            if (!script.enableReflections)
            {
                GUI.contentColor    = colorDisabled;
                GUI.backgroundColor = colorDisabled;
            }
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 103, 160, 18), "WATER REFLECTIONS");
            EditorGUI.LabelField(new Rect(rt.x + margin + 50, rt.y + 123, 170, 18), "Enable Dynamic Reflections");
            script.enableDynamicReflections = EditorGUI.Toggle(new Rect(rt.x + margin + 30, rt.y + 123, setWidth, 18), "", script.enableDynamicReflections);
            GUI.contentColor    = colorEnabled;
            GUI.backgroundColor = colorEnabled;



            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin + 10, rt.y + 145, 372, 1), divHorizTex);
            script.enableCaustics = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 150, 20, 18), "", script.enableCaustics);

            if (!script.enableCaustics)
            {
                GUI.contentColor    = colorDisabled;
                GUI.backgroundColor = colorDisabled;
            }

            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 150, 160, 18), "CAUSTIC FX");

            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 170, 140, 18), "FPS");
            script.suimonoModuleLibrary.causticObject.causticFPS = EditorGUI.IntField(new Rect(rt.x + margin + 30, rt.y + 185, 30, 18), "", script.suimonoModuleLibrary.causticObject.causticFPS);

            EditorGUI.LabelField(new Rect(rt.x + margin + 90, rt.y + 170, 140, 18), "Caustic Tint");
            script.suimonoModuleLibrary.causticObject.causticTint = EditorGUI.ColorField(new Rect(rt.x + margin + 90, rt.y + 187, 120, 14), "", script.suimonoModuleLibrary.causticObject.causticTint);

            EditorGUI.LabelField(new Rect(rt.x + margin + 230, rt.y + 170, 100, 18), "Render Layers");
            if (script.gameObject.activeInHierarchy)
            {
                script.causticLayer = EditorGUI.MaskField(new Rect(rt.x + margin + 230, rt.y + 187, 155, 18), "", script.causticLayer, script.suiLayerMasks.ToArray());
            }

            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 210, 100, 18), "Bright");
            script.suimonoModuleLibrary.causticObject.causticIntensity = EditorGUI.Slider(new Rect(rt.x + margin + 90, rt.y + 210, 120, 18), "", script.suimonoModuleLibrary.causticObject.causticIntensity, 0.0f, 3.0f);

            EditorGUI.LabelField(new Rect(rt.x + margin + 230, rt.y + 210, 80, 18), "Scale");
            script.suimonoModuleLibrary.causticObject.causticScale = EditorGUI.Slider(new Rect(rt.x + margin + 275, rt.y + 210, 115, 18), "", script.suimonoModuleLibrary.causticObject.causticScale, 0.5f, 15.0f);

            if (script.setLight == null)
            {
                GUI.contentColor    = colorDisabled;
                GUI.backgroundColor = colorDisabled;
            }
            script.suimonoModuleLibrary.causticObject.inheritLightColor = EditorGUI.Toggle(new Rect(rt.x + margin + 30, rt.y + 235, 120, 18), "", script.suimonoModuleLibrary.causticObject.inheritLightColor);
            EditorGUI.LabelField(new Rect(rt.x + margin + 50, rt.y + 235, 140, 18), "Inherit Light Color");
            script.suimonoModuleLibrary.causticObject.inheritLightDirection = EditorGUI.Toggle(new Rect(rt.x + margin + 200, rt.y + 235, 120, 18), "", script.suimonoModuleLibrary.causticObject.inheritLightDirection);
            EditorGUI.LabelField(new Rect(rt.x + margin + 220, rt.y + 235, 140, 18), "Inherit Light Direction");

            if (script.enableCaustics)
            {
                GUI.contentColor    = colorEnabled;
                GUI.backgroundColor = colorEnabled;
            }
            script.enableCausticsBlending = EditorGUI.Toggle(new Rect(rt.x + margin + 30, rt.y + 255, 120, 18), "", script.enableCausticsBlending);
            EditorGUI.LabelField(new Rect(rt.x + margin + 50, rt.y + 255, 320, 18), "Enable Advanced Caustic FX (effects performance)");

            GUI.contentColor    = colorEnabled;
            GUI.backgroundColor = colorEnabled;



            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin + 10, rt.y + 285, 372, 1), divHorizTex);
            script.enableAdvancedDistort = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 290, 20, 18), "", script.enableAdvancedDistort);
            if (!script.enableAdvancedDistort)
            {
                GUI.contentColor    = colorDisabled;
                GUI.backgroundColor = colorDisabled;
            }
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 290, 340, 18), "ADVANCED WAKE AND DISTORTION EFFECTS");
            GUI.contentColor    = colorDisabled;
            GUI.backgroundColor = colorDisabled;
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 305, 340, 18), "Enables rendering of advanced scene effects such as wake");
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 317, 340, 18), "and boat trail generation and water ripple distortion fx.");
            GUI.contentColor    = colorEnabled;
            GUI.backgroundColor = colorEnabled;



            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin + 10, rt.y + 340, 372, 1), divHorizTex);
            script.enableAutoAdvance = EditorGUI.Toggle(new Rect(rt.x + margin + 10, rt.y + 345, 20, 18), "", script.enableAutoAdvance);
            if (!script.enableAutoAdvance)
            {
                GUI.contentColor    = colorDisabled;
                GUI.backgroundColor = colorDisabled;
            }
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 345, 340, 18), "AUTO-ADVANCE SYSTEM TIMER");
            script.systemTime = EditorGUI.FloatField(new Rect(rt.x + margin + 260, rt.y + 345, 120, 18), "", script.systemTime);


            GUI.contentColor    = colorDisabled;
            GUI.backgroundColor = colorDisabled;
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 360, 340, 18), "the 'systemTime' variable is automatically advanced by");
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 372, 340, 18), "default.  This variable can be shared across a network to");
            EditorGUI.LabelField(new Rect(rt.x + margin + 30, rt.y + 384, 340, 18), "sync wave positions between client and server computers.");


            GUI.contentColor    = colorEnabled;
            GUI.backgroundColor = colorEnabled;



            GUILayout.Space(390.0f);
        }
        GUILayout.Space(10.0f);



        if (script.useTenkoku == 1.0f)
        {
            rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
            EditorGUI.DrawPreviewTexture(new Rect(rt.x + margin, rt.y, 387, 24), divTex);
            script.showTenkoku = EditorGUI.Foldout(new Rect(rt.x + margin + 3, rt.y + 5, 20, 20), script.showTenkoku, "");
            GUI.Label(new Rect(rt.x + margin + 20, rt.y + 5, 300, 20), new GUIContent("TENKOKU SKY SYSTEM - INTEGRATION"));

            if (script.showTenkoku)
            {
                EditorGUI.LabelField(new Rect(rt.x + margin + 10, rt.y + 30, 140, 18), "Use Wind Settings");
                script.tenkokuUseWind = EditorGUI.Toggle(new Rect(rt.x + margin + 125, rt.y + 30, setWidth, 18), "", script.tenkokuUseWind);

                EditorGUI.LabelField(new Rect(rt.x + margin + 195, rt.y + 30, 150, 18), "Calculate Sky Reflections");
                script.tenkokuUseReflect = EditorGUI.Toggle(new Rect(rt.x + margin + 350, rt.y + 30, setWidth, 18), "", script.tenkokuUseReflect);
            }
            GUILayout.Space(50.0f);
        }
        GUILayout.Space(10.0f);


        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Beispiel #17
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        SwiftShadow.LightVectorSourceEnum lightVectorSource = (SwiftShadow.LightVectorSourceEnum)DoFieldProperty <int>(
            _lightVectorSource,
            new GUIContent(
                "Light direction from: ",
                ""
                ),
            "LightVectorSource",
            (rect, label, property) =>
            EditorGUI.Popup(rect, label, property.enumValueIndex, EditorGUIUtilityInternal.TempContent(new string[] { "Static vector", "Light source object" })));

        EditorGUI.indentLevel++;
        if (lightVectorSource == SwiftShadow.LightVectorSourceEnum.StaticVector)
        {
            DoFieldProperty(
                _lightVector,
                new GUIContent(
                    "Direction vector: ",
                    "Light direction vector relative to the object. For example, (0, -1, 0) means the light always come from right above."
                    ),
                "LightVector",
                (rect, label, property) => EditorGUI.Vector3Field(rect, label.text, property.vector3Value));
        }
        else
        {
            Transform lightSourceObject = DoFieldProperty <Transform>(
                _lightSourceObject,
                new GUIContent(
                    "Light source: ",
                    "The GameObject that'll be used as point light source for this shadow."
                    ),
                "LightSourceObject",
                (rect, label, property) => (Transform)EditorGUI.ObjectField(rect, label, property.objectReferenceValue, typeof(Transform), true));

            if (lightSourceObject == null)
            {
                EditorGUILayout.HelpBox("No light source selected. Shadow will use the static vector instead.", MessageType.Warning, false);
            }
        }
        EditorGUI.indentLevel--;

        DoFieldProperty <LayerMask>(
            _layerMask,
            new GUIContent(
                "Raycast layer mask: ",
                "Layers to cast shadows on. " +
                "You must to exclude the layer of the object " +
                "itself if it has a collider attached to it, otherwise shadow may behave strange."
                ),
            "LayerMask",
            (rect, label, property) => {
            EditorGUIInternal.LayerMaskField(rect, property, label);
            return(0);
        });

        if (_layerMask.intValue == 0)
        {
            EditorGUILayout.HelpBox("No layer mask is set. Shadows won't project on anything.", MessageType.Warning, false);
        }

        EditorGUILayout.HelpBox("Shadow", MessageType.None, true);

        Material shadowMaterial = DoFieldProperty(
            _material,
            new GUIContent(
                "Material: ",
                "Material that'll be used for rendering the shadow."
                ),
            "Material",
            (rect, label, property) => (Material)EditorGUI.ObjectField(rect, label, property.objectReferenceValue, typeof(Material), false));

        if (shadowMaterial == null)
        {
            EditorGUILayout.HelpBox("No material assigned. Shadow will use the default blob shadow.", MessageType.Info, false);
        }

        DoFieldProperty(
            _color,
            new GUIContent(
                "Shadow color: ",
                "The color of the shadow."
                ),
            "Color",
            (rect, label, property) => EditorGUI.ColorField(rect, label, property.colorValue));

        DoFieldProperty(
            _shadowSize,
            new GUIContent(
                "Shadow size: ",
                "Scale of shadow relative to object's max dimensions."
                ),
            "ShadowSize",
            (rect, label, property) => EditorGUI.FloatField(rect, label, property.floatValue));

        EditorGUILayout.BeginHorizontal();
#if !UNITY_3_5
        GUILayout.Space(EditorGUIUtilityInternal.labelWidth);
#else
        GUILayout.Space(EditorGUIUtilityInternal.labelWidth + 4f);
#endif

        if (GUILayout.Button("Estimate size"))
        {
            GUI.changed = true;

            foreach (Object targetObject in _shadowSize.serializedObject.targetObjects)
            {
                SwiftShadow shadow     = (SwiftShadow)targetObject;
                GameObject  go         = shadow.gameObject;
                Quaternion  goRotation = go.transform.rotation;
                go.transform.rotation = Quaternion.identity;

                Bounds bounds = new Bounds(go.transform.position, Vector3.zero);
                foreach (Renderer renderer in go.GetComponentsInChildren <Renderer>())
                {
                    bounds.Encapsulate(renderer.bounds);
                }

                if (bounds.size.magnitude > Vector3.kEpsilon)
                {
                    float scaleMin = Mathf.Min(go.transform.lossyScale.x, go.transform.lossyScale.y, go.transform.lossyScale.z);
                    shadow.ShadowSize = Mathf.Max(bounds.size.x, bounds.size.y, bounds.size.z) / scaleMin;
                    shadow.ShadowSize = (float)Math.Round(shadow.ShadowSize, 5);
                }
                go.transform.rotation = goRotation;
            }
            _shadowSize.serializedObject.ApplyModifiedProperties();
            _shadowSize.serializedObject.SetIsDifferentCacheDirty();

            Repaint();
        }

        EditorGUILayout.EndHorizontal();

        GUI.enabled = lightVectorSource == SwiftShadow.LightVectorSourceEnum.GameObject;
        DoFieldProperty(
            _isPerspectiveProjection,
            new GUIContent(
                "Perspective projection: ",
                "Makes shadows bigger as they move away from the light source. " +
                "This usually looks more realistic, but may result in artifacts at extreme angles."
                ),
            "IsPerspectiveProjection",
            (rect, label, property) => EditorGUI.Toggle(rect, label, property.boolValue));
        GUI.enabled = true;

        DoFieldProperty(
            _projectionDistance,
            new GUIContent(
                "Projection distance: ",
                "Maximal distance from the transform position to the surface shadow will fall on."
                ),
            "ProjectionDistance",
            (rect, label, property) => EditorGUI.FloatField(rect, label, property.floatValue));

        EditorGUI.indentLevel++;
        EditorGUILayout.BeginHorizontal(GUILayout.Width(100f));
        EditorGUILayout.HelpBox("Fading", MessageType.None, true);
        EditorGUILayout.EndHorizontal();

        DoFieldProperty(
            _fadeDistance,
            new GUIContent(
                "Fade distance: ",
                "Distance at which shadow will start fading out. Used for smooth transition to \"Projection distance\""
                ),
            "FadeDistance",
            (rect, label, property) => EditorGUI.FloatField(rect, label, property.floatValue));

        DoFieldProperty(
            _angleFadeMin,
            new GUIContent(
                "Angle fade from: ",
                "The angle at which the shadow will start fading out. Used for smooth transition to \"Max angle\""
                ),
            "AngleFadeMin",
            (rect, label, property) => EditorGUI.FloatField(rect, label, property.floatValue));

        DoFieldProperty(
            _angleFadeMax,
            new GUIContent(
                "Max angle: ",
                "The maximum angle at which the shadow is allowed to fall on surface. " +
                "It it falls at a bigger angle, no shadow will be rendered."
                ),
            "AngleFadeMax",
            (rect, label, property) => EditorGUI.FloatField(rect, label, property.floatValue));

        EditorGUILayout.BeginHorizontal(GUILayout.Width(100f));
        EditorGUILayout.HelpBox("Static", MessageType.None, true);
        EditorGUILayout.EndHorizontal();

        DoFieldProperty(
            _isStatic,
            new GUIContent(
                "Static: ",
                "If checked, the shadow will be calculated only at the creation. " +
                "Use this for shadows that do not move for a huge perfomance boost."),
            "IsStatic",
            (rect, label, property) => {
            EditorGUILayout.BeginHorizontal();

            Rect labelRect  = rect;
            labelRect.width = GUI.skin.label.CalcSize(label).x + EditorGUILayoutExtensions.kIndentationWidth;
            labelRect.xMin += EditorGUILayoutExtensions.kIndentationWidth;
            rect.xMin       = labelRect.xMax;

            GUI.Label(labelRect, label);
            bool result = EditorGUI.Toggle(rect, property.boolValue);
            EditorGUILayout.EndHorizontal();

            return(result);
        });

        DoFieldProperty(
            _autoStaticTime,
            new GUIContent(
                "Set to static if not moving for",
                "Makes shadow static if it hasn't moved for X seconds. " +
                "Shadow will return to non-static state when moving or rotating. " +
                "This is useful for optimizing performance if you have shadow that " +
                "only move from time to time. Value of 0 disables this setting."
                ),
            "AutoStaticTime",
            (rect, label, property) => {
            GUIContent secText = new GUIContent("sec.");

            Rect labelRect  = rect;
            labelRect.width = GUI.skin.label.CalcSize(label).x + EditorGUILayoutExtensions.kIndentationWidth;
            labelRect.xMin += EditorGUILayoutExtensions.kIndentationWidth;
            rect.xMin       = labelRect.xMax;

            GUI.Label(labelRect, label);

            labelRect      = rect;
            labelRect.xMin = rect.xMax - GUI.skin.label.CalcSize(secText).x;

            rect.xMax = labelRect.xMin;

            float result = EditorGUI.FloatField(rect, property.floatValue);

            GUI.Label(labelRect, secText);

            return(result);
        }
            );

        EditorGUI.indentLevel--;
        EditorGUILayout.HelpBox("Advanced", MessageType.None, true);

        DoFieldProperty(
            _textureUVRect,
            new GUIContent(
                "Texture coordinates: ",
                "The texture coordinates of shadow. Change this to use multiple shadow cookies within the material texture."
                ),
            "TextureUVRect",
            (rect, label, property) => EditorGUI.RectField(rect, label, property.rectValue));

        DoFieldProperty(
            _aspectRatio,
            new GUIContent("Aspect ratio: ", "The width/height aspect ratio of shadow."),
            "AspectRatio",
            (rect, label, property) => EditorGUI.FloatField(rect, label, property.floatValue));

        DoFieldProperty(
            _shadowOffset,
            new GUIContent(
                "Shadow offset: ",
                "The distance at which the shadow hovers above the surface. " +
                "Increase this value if you see shadows flickering due to Z-fighting"
                ),
            "ShadowOffset",
            (rect, label, property) => EditorGUI.FloatField(rect, label, property.floatValue));

        DoFieldProperty(
            _frameSkip,
            new GUIContent(
                "Frame skip: ",
                "Skip N frames before updating the shadow. " +
                "Can be useful if you don't need to update shadow too often."
                ),
            "FrameSkip",
            (rect, label, property) => EditorGUI.IntSlider(rect, label, property.intValue, 0, 50));

        DoFieldProperty(
            _cullInvisible,
            new GUIContent(
                "Ignore culling: ",
                "If selected, the camera culling will be disabled. " +
                "Check this for a small performance gain if shadow is always in sight."
                ),
            "CullInvisible",
            (rect, label, property) => !EditorGUI.Toggle(rect, label, !property.boolValue));

        bool useForceLayer = DoFieldProperty(
            _useForceLayer,
            new GUIContent(
                "Shadow layer: ",
                "The layer at which the shadow will be rendered."
                ),
            "UseForceLayer",
            (rect, label, property) =>
            EditorGUI.Popup(rect, label, property.boolValue ? 1 : 0, EditorGUIUtilityInternal.TempContent(new string[] { "Same as GameObject", "Manual" })) == 1);

        if (useForceLayer)
        {
            EditorGUI.indentLevel++;
            DoFieldProperty(
                _forceLayer,
                new GUIContent(
                    "Layer: ",
                    ""
                    ),
                "ForceLayer",
                (rect, label, property) => EditorGUI.LayerField(rect, label, _forceLayer.intValue));
            EditorGUI.indentLevel--;
        }

        serializedObject.ApplyModifiedProperties();
    }
    public override void OnGUI(Rect pRect, SerializedProperty pProperty, GUIContent pLabel)
    {
        GUI.enabled = false;
        switch (pProperty.propertyType)
        {
        case SerializedPropertyType.Integer:
            EditorGUI.LabelField(pRect, pLabel.text, pProperty.intValue.ToString());
            break;

        case SerializedPropertyType.Boolean:
            EditorGUI.LabelField(pRect, pLabel.text, pProperty.boolValue.ToString());
            break;

        case SerializedPropertyType.Float:
            EditorGUI.LabelField(pRect, pLabel.text, pProperty.floatValue.ToString("0.00000"));
            break;

        case SerializedPropertyType.String:
        case SerializedPropertyType.Character:
            EditorGUI.LabelField(pRect, pLabel.text, pProperty.stringValue);
            break;

        case SerializedPropertyType.Color:
            EditorGUI.ColorField(pRect, pLabel.text, pProperty.colorValue);
            break;

        case SerializedPropertyType.ObjectReference:
            EditorGUI.ObjectField(pRect, pLabel.text, pProperty.objectReferenceValue, typeof(System.Object), true);
            break;

        case SerializedPropertyType.Vector2:
            EditorGUI.Vector2Field(pRect, pLabel.text, pProperty.vector2Value);
            break;

        case SerializedPropertyType.Vector3:
            EditorGUI.Vector3Field(pRect, pLabel.text, pProperty.vector3Value);
            break;

        case SerializedPropertyType.Vector4:
            EditorGUI.Vector4Field(pRect, pLabel.text, pProperty.vector4Value);
            break;

        case SerializedPropertyType.Quaternion:
            EditorGUI.LabelField(pRect, pLabel.text, pProperty.quaternionValue.ToString());
            break;

        case SerializedPropertyType.Rect:
            EditorGUI.RectField(pRect, pLabel.text, pProperty.rectValue);
            break;

        case SerializedPropertyType.ArraySize:
            EditorGUI.LabelField(pRect, pLabel.text, pProperty.arraySize.ToString());
            break;

        case SerializedPropertyType.AnimationCurve:
            EditorGUI.CurveField(pRect, pLabel.text, pProperty.animationCurveValue);
            break;

        case SerializedPropertyType.Bounds:
            EditorGUI.BoundsField(pRect, pProperty.boundsValue);
            break;

        case SerializedPropertyType.Gradient:
        default:
            EditorGUI.LabelField(pRect, pLabel.text, "(not supported)");
            break;
        }
        GUI.enabled = true;
    }
        protected virtual void DrawEvent(Rect rect, int index, bool isActive, bool isFocused)
        {
            var pListener = m_ListenersArray.GetArrayElementAtIndex(index);

            rect.y++;
            Rect[] subRects     = GetRowRects(rect);
            Rect   enabledRect  = subRects[0];
            Rect   goRect       = subRects[1];
            Rect   functionRect = subRects[2];
            Rect   argRect      = subRects[3];

            // find the current event target...
            var callState      = pListener.FindPropertyRelative(kCallStatePath);
            var mode           = pListener.FindPropertyRelative(kModePath);
            var arguments      = pListener.FindPropertyRelative(kArgumentsPath);
            var listenerTarget = pListener.FindPropertyRelative(kInstancePath);
            var methodName     = pListener.FindPropertyRelative(kMethodNamePath);

            Color c = GUI.backgroundColor;

            GUI.backgroundColor = Color.white;

            EditorGUI.PropertyField(enabledRect, callState, GUIContent.none);

            EditorGUI.BeginChangeCheck();
            {
                GUI.Box(goRect, GUIContent.none);
                EditorGUI.PropertyField(goRect, listenerTarget, GUIContent.none);
                if (EditorGUI.EndChangeCheck())
                {
                    methodName.stringValue = null;
                }
            }

            SerializedProperty argument;
            var modeEnum = GetMode(mode);

            //only allow argument if we have a valid target / method
            if (listenerTarget.objectReferenceValue == null || string.IsNullOrEmpty(methodName.stringValue))
            {
                modeEnum = UnityEngine.Events.PersistentListenerMode.Void;
            }

            System.Type desiredDataType = null;
            switch (modeEnum)
            {
            case UnityEngine.Events.PersistentListenerMode.Float:
                argument = arguments.FindPropertyRelative(kFloatArgument);
                break;

            case UnityEngine.Events.PersistentListenerMode.Int:
                argument = arguments.FindPropertyRelative(kIntArgument);
                break;

            case UnityEngine.Events.PersistentListenerMode.Object:
                argument = arguments.FindPropertyRelative(kObjectArgument);
                break;

            case UnityEngine.Events.PersistentListenerMode.String:
            {
                var desiredDataTypeName = arguments.FindPropertyRelative(kSerializedDataArgumentAssemblyTypeName).stringValue;
                desiredDataType = typeof(object);
                if (!string.IsNullOrEmpty(desiredDataTypeName))
                {
                    desiredDataType = Type.GetType(desiredDataTypeName, false) ?? typeof(string);
                }
                else
                {
                    desiredDataType = typeof(string);
                }

                if (desiredDataType != null && desiredDataType != typeof(string))
                {
                    argument = arguments.FindPropertyRelative(kSerializedDataArgument);
                }
                else
                {
                    argument = arguments.FindPropertyRelative(kStringArgument);
                }
                break;
            }

            case UnityEngine.Events.PersistentListenerMode.Bool:
                argument = arguments.FindPropertyRelative(kBoolArgument);
                break;

            default:
                argument = arguments.FindPropertyRelative(kIntArgument);
                break;
            }

            var desiredArgTypeName = arguments.FindPropertyRelative(kObjectArgumentAssemblyTypeName).stringValue;
            var desiredType        = typeof(Object);

            if (!string.IsNullOrEmpty(desiredArgTypeName))
            {
                desiredType = Type.GetType(desiredArgTypeName, false) ?? typeof(Object);
            }

            if (modeEnum == UnityEngine.Events.PersistentListenerMode.Object)
            {
                EditorGUI.BeginChangeCheck();
                var result = EditorGUI.ObjectField(argRect, GUIContent.none, argument.objectReferenceValue, desiredType, true);
                if (EditorGUI.EndChangeCheck())
                {
                    argument.objectReferenceValue = result;
                }
            }
            else if (modeEnum != UnityEngine.Events.PersistentListenerMode.Void && modeEnum != UnityEngine.Events.PersistentListenerMode.EventDefined)
            {
                var drawDefault = false;
                if (modeEnum == UnityEngine.Events.PersistentListenerMode.String && desiredDataType != null && desiredDataType != typeof(string))
                {
                    try
                    {
                        if (desiredDataType.IsSubclassOf(typeof(Color)) || desiredDataType == typeof(Color) || desiredDataType.IsSubclassOf(typeof(Color32)) || desiredDataType == typeof(Color32))
                        {
                            var color    = string.IsNullOrEmpty(argument.stringValue) ? Color.clear : (Color)ArgumentCacheEx.FromJson(argument.stringValue, desiredDataType);
                            var newColor = EditorGUI.ColorField(argRect, color);
                            if (color != newColor)
                            {
                                argument.stringValue = ArgumentCacheEx.ToJson(newColor);
                            }
                        }
                        else if (desiredDataType.IsEnum)
                        {
                            var enumValue = string.IsNullOrEmpty(argument.stringValue) ? (System.Enum)System.Enum.ToObject(desiredDataType, 0) : (System.Enum)ArgumentCacheEx.FromJson(argument.stringValue, desiredDataType);
                            var newValue  = EditorGUI.EnumPopup(argRect, enumValue);
                            if (enumValue != newValue)
                            {
                                argument.stringValue = ArgumentCacheEx.ToJson(newValue);
                            }
                        }
                        else
                        {
                            drawDefault = true;
                        }
                    }
                    catch (UnityEngine.ExitGUIException)
                    {
                        throw;
                    }
                    catch
                    {
                        argument.stringValue = "";
                        drawDefault          = true;
                    }
                }
                else
                {
                    drawDefault = true;
                }

                if (drawDefault)
                {
                    EditorGUI.PropertyField(argRect, argument, GUIContent.none);
                }
            }

            using (new EditorGUI.DisabledScope(listenerTarget.objectReferenceValue == null))
            {
                EditorGUI.BeginProperty(functionRect, GUIContent.none, methodName);
                {
                    GUIContent buttonContent;
                    if (EditorGUI.showMixedValue)
                    {
                        buttonContent = s_MixedValueContent;
                    }
                    else
                    {
                        var buttonLabel = new StringBuilder();
                        if (listenerTarget.objectReferenceValue == null || string.IsNullOrEmpty(methodName.stringValue))
                        {
                            buttonLabel.Append(kNoFunctionString);
                        }
                        else if (!IsPersistantListenerValid(m_DummyEvent, methodName.stringValue, listenerTarget.objectReferenceValue, GetMode(mode), GetMode(mode) == UnityEngine.Events.PersistentListenerMode.String? desiredDataType : desiredType))
                        {
                            var instanceString = "UnknownComponent";
                            var instance       = listenerTarget.objectReferenceValue;
                            if (instance != null)
                            {
                                instanceString = instance.GetType().Name;
                            }

                            buttonLabel.Append(string.Format("<Missing {0}.{1}>", instanceString, methodName.stringValue));
                        }
                        else
                        {
                            buttonLabel.Append(listenerTarget.objectReferenceValue.GetType().Name);

                            if (!string.IsNullOrEmpty(methodName.stringValue))
                            {
                                buttonLabel.Append(".");
                                if (methodName.stringValue.StartsWith("set_"))
                                {
                                    buttonLabel.Append(methodName.stringValue.Substring(4));
                                }
                                else
                                {
                                    buttonLabel.Append(methodName.stringValue);
                                }
                            }
                        }
                        buttonContent = new GUIContent(buttonLabel.ToString());
                    }

                    if (GUI.Button(functionRect, buttonContent, EditorStyles.popup))
                    {
                        BuildPopupList(listenerTarget.objectReferenceValue, m_DummyEvent, pListener).DropDown(functionRect);
                    }
                }
                EditorGUI.EndProperty();
            }
            GUI.backgroundColor = c;
        }
        static void DisplayProperty(ref VFXParameterInfo parameter, GUIContent nameContent, SerializedProperty overridenProperty, SerializedProperty valueProperty)
        {
            EditorGUILayout.BeginHorizontal();

            var height = 16f;

            if (EditorGUIUtility.currentViewWidth < 333f && GenerateMultipleField(ref parameter, valueProperty))
            {
                height *= 2.0f;
            }

            var rect = EditorGUILayout.GetControlRect(false, height);

            var toggleRect = rect;

            toggleRect.x               += EditorGUI.indentLevel * 16;
            toggleRect.yMin            += 1.0f;
            toggleRect.width            = 18;
            overridenProperty.boolValue = EditorGUI.Toggle(toggleRect, overridenProperty.hasMultipleDifferentValues ? false : overridenProperty.boolValue, overridenProperty.hasMultipleDifferentValues ? Styles.toggleMixedStyle : Styles.toggleStyle);
            rect.xMin += overrideWidth + EditorGUI.indentLevel * 16;

            int saveIndent = EditorGUI.indentLevel; // since we already applied the indentLevel to the rect reset it to zero.

            EditorGUI.indentLevel = 0;

            EditorGUI.BeginProperty(rect, nameContent, valueProperty);

            if (parameter.min != Mathf.NegativeInfinity && parameter.max != Mathf.Infinity)
            {
                if (valueProperty.propertyType == SerializedPropertyType.Float)
                {
                    EditorGUI.Slider(rect, valueProperty, parameter.min, parameter.max, nameContent);
                }
                else
                {
                    EditorGUI.IntSlider(rect, valueProperty, (int)parameter.min, (int)parameter.max, nameContent);
                }
            }
            else if (parameter.realType == typeof(Color).Name)
            {
                Vector4 vVal = valueProperty.vector4Value;
                Color   c    = new Color(vVal.x, vVal.y, vVal.z, vVal.w);
                c = EditorGUI.ColorField(rect, nameContent, c, true, true, true);

                if (GUI.changed)
                {
                    valueProperty.vector4Value = new Vector4(c.r, c.g, c.b, c.a);
                }
            }
            else if (parameter.realType == typeof(Gradient).Name)
            {
                Gradient newGradient = EditorGUI.GradientField(rect, nameContent, valueProperty.gradientValue, true);

                if (GUI.changed)
                {
                    valueProperty.gradientValue = newGradient;
                }
            }
            else if (valueProperty.propertyType == SerializedPropertyType.Vector4)
            {
                SerializedProperty copy = valueProperty.Copy();
                copy.Next(true);
                EditorGUI.MultiPropertyField(rect, new GUIContent[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z"), new GUIContent("W") }, copy, nameContent);
            }
            else if (valueProperty.propertyType == SerializedPropertyType.ObjectReference)
            {
                Type objTyp = typeof(UnityObject);
                if (!string.IsNullOrEmpty(parameter.realType))
                {
                    if (parameter.realType.StartsWith("Texture") || parameter.realType.StartsWith("Cubemap"))
                    {
                        objTyp = typeof(Texture);
                    }
                    else if (parameter.realType == "Mesh")
                    {
                        objTyp = typeof(Mesh);
                    }
                }
                EditorGUI.ObjectField(rect, valueProperty, objTyp, nameContent);
            }
            else
            {
                EditorGUI.PropertyField(rect, valueProperty, nameContent, true);
            }
            EditorGUI.indentLevel = saveIndent;
            EditorGUI.EndProperty();
            EditorGUILayout.EndHorizontal();
        }
Beispiel #21
0
        // 类别列表信息
        private void InitTab()
        {
            menuReorderableList = new ReorderableList(CurBackupDataLst, CurBackupDataLst.GetType())
            {
                elementHeight       = 20,
                drawElementCallback = (rect, index, isActive, isFocused) =>
                {
                    if (index >= CurBackupDataLst.Count || CurBackupDataLst[index] == null)
                    {
                        return;
                    }

                    var labelRect = new Rect(rect.x, rect.y, 60, 20);
                    GUI.Label(labelRect, "数量-" + CurBackupDataLst[index].TileDataLst.Count.ToString());

                    var iconTipRect = new Rect(rect.x + 60, rect.y, 50, 15);
                    GUI.Label(iconTipRect, "图标-");
                    var iconNameRect = new Rect(rect.x + 110, rect.y, 30, 15);
                    CurBackupDataLst[index].IconName = EditorGUI.TextField(iconNameRect, CurBackupDataLst[index].IconName);

                    var sizeLabelRect = new Rect(rect.x + 140, rect.y, 40, 15);
                    GUI.Label(sizeLabelRect, "点大小-");
                    var pointRect = new Rect(rect.x + 180, rect.y, 40, 15);
                    CurBackupDataLst[index].PointSize = EditorGUI.FloatField(pointRect, CurBackupDataLst[index].PointSize);

                    var longTipRect = new Rect(rect.x + 220, rect.y, 40, 15);
                    GUI.Label(longTipRect, "范围-");
                    var longXRect = new Rect(rect.x + 260, rect.y, 20, 15);
                    var longYRect = new Rect(rect.x + 280, rect.y, 20, 15);

                    // 范围
                    CurBackupDataLst[index].LongX = EditorGUI.IntField(longXRect, CurBackupDataLst[index].LongX);
                    CurBackupDataLst[index].LongY = EditorGUI.IntField(longYRect, CurBackupDataLst[index].LongY);

                    var colorRect = new Rect(rect.x + 300, rect.y, 50, 15);
                    var btnRect   = new Rect(rect.x + 370, rect.y, 80, 15);
                    CurBackupDataLst[index].Color = EditorGUI.ColorField(colorRect, CurBackupDataLst[index].Color);

                    if (GUI.Button(btnRect, "详细列表O"))
                    {
                        // 设置正在使用的列表
                        CurChooseIndex = index;
                    }
                },

                // 添加类别
                onAddCallback = delegate
                {
                    CurBackupDataLst.Add(
                        new TileTarget
                    {
                        TileDataLst = new List <TileData>(),
                    });
                },

                // 删除
                onRemoveCallback = delegate
                {
                    var isDelete = EditorUtility.DisplayDialog("Tip", "Do you want to delete it?", "Delete", "Cancle");

                    if (isDelete)
                    {
                        CurBackupDataLst.RemoveAt(menuReorderableList.index);
                        CurChooseIndex = Mathf.Max(0, CurBackupDataLst.Count - 1);
                    }
                },

                // 修改
                onChangedCallback = (list) =>
                {
                    _isReorderableListChange = true;
                }
            };

            menuReorderableList.drawHeaderCallback = (Rect rect) => { GUI.Label(rect, RECORED_TITLE); };
            menuReorderableList.onSelectCallback   = (list) =>
            {
                int index = menuReorderableList.index;
            };
        }
Beispiel #22
0
        /// <summary>
        /// Handles draw list element.
        /// </summary>
        /// <param name="rect">Rect.</param>
        /// <param name="index">Index.</param>
        /// <param name="isActive">If set to <c>true</c> is active.</param>
        /// <param name="isFocused">If set to <c>true</c> is focused.</param>
        private static void onDrawElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            EditorClipBinding clipBindingCurrent = __gameObjectClipList.list [index] as EditorClipBinding;

            if (clipBindingCurrent == null)
            {
                return;
            }



            float width = rect.xMax;

            rect.xMax = 200f;



            /////////////  ADD GAMEOBJECT TO CLIPBINDING  /////////

            EditorGUI.BeginChangeCheck();

            GameObject gameObjectHolderBinded = EditorGUI.ObjectField(rect, clipBindingCurrent.gameObject, typeof(GameObject), true) as GameObject;


            if (EditorGUI.EndChangeCheck() && gameObjectHolderBinded != null && gameObjectHolderBinded.transform.childCount == 1)
            {
                clipBindingCurrent.gameObject = gameObjectHolderBinded;

                clipBindingCurrent.positionOffset = Quaternion.Inverse(__spaceGameObject.transform.rotation) * (clipBindingCurrent.gameObject.transform.position - __spaceGameObject.transform.position);
                clipBindingCurrent.rotationOffset = Quaternion.Inverse(__spaceGameObject.transform.rotation) * gameObjectHolderBinded.transform.rotation;
            }



            rect.xMin = rect.xMax + 2;
            rect.xMax = width - 100f;



            /////////////  ADD ANIMATION CLIP TO CLIPBINDING  /////////

            clipBindingCurrent.clip = EditorGUI.ObjectField(rect, clipBindingCurrent.clip, typeof(AnimationClip), true) as AnimationClip;

            if (clipBindingCurrent.clip == null)
            {
                rect.xMin = rect.xMax + 2;
                rect.xMax = rect.xMin + 30f;

                if (GUI.Button(rect, "New Clip"))
                {
                    string path = EditorUtility.SaveFilePanel(
                        "Create New Clip",
                        "Assets",
                        "",
                        "anim");

                    if (!String.IsNullOrEmpty(path))
                    {
                        AnimationClip clip = new AnimationClip();                                                                         //UnityEditor.Animations.AnimatorController.AllocateAnimatorClip ();
                        clip.name = Path.GetFileNameWithoutExtension(path);
                        AssetDatabase.CreateAsset(clip, AssetDatabaseUtility.AbsoluteUrlToAssets(path));
                        AssetDatabase.SaveAssets();
                        clipBindingCurrent.clip           = clip;
                        clipBindingCurrent.clip.frameRate = __spaceGameObjectAnimationClip.frameRate;
                    }
                }
            }


            /////////////  COLOR PATH CLIPBINDING  /////////
            rect.xMin = rect.xMax + 2f;
            rect.xMax = rect.xMin + 30f;
            clipBindingCurrent.color = EditorGUI.ColorField(rect, clipBindingCurrent.color);


            /////////////  CLIPBINDING PATH SHOW/HIDE  /////////
            rect.xMin = rect.xMax + 2f;
            rect.xMax = width;
            clipBindingCurrent.visible = EditorGUI.Toggle(rect, clipBindingCurrent.visible);
        }
        private void RenderField(Rect rect, WeatherMakerPropertyTransition t, MemberInfo member, float textFieldWidth)
        {
            if (t == null || member == null)
            {
                return;
            }
            string                   tooltip = null;
            RangeAttribute           range   = null;
            SingleLineClampAttribute clamp   = null;

            object[] attributes = member.GetCustomAttributes(false);
            foreach (object obj in attributes)
            {
                if (obj is TooltipAttribute)
                {
                    tooltip = (obj as TooltipAttribute).tooltip;
                }
                else if (obj is SingleLineAttribute)
                {
                    tooltip = (obj as SingleLineAttribute).Tooltip;
                }
                else if (obj is RangeAttribute)
                {
                    range = obj as RangeAttribute;
                }
                else if (obj is SingleLineClampAttribute)
                {
                    clamp = obj as SingleLineClampAttribute;
                }
            }
            GUIContent label = new GUIContent("Value", tooltip);

            EditorGUIUtility.fieldWidth = 70.0f;
            Type type = member.GetUnderlyingType();

            if (type == typeof(float))
            {
                RenderFloatField(rect, t, label, member, range, clamp);
            }
            else if (type == typeof(int))
            {
                RenderIntField(rect, t, label, member, range, clamp);
            }
            else if (type == typeof(bool))
            {
                t.Value = EditorGUI.Toggle(rect, label, (bool)GetMemberValue(member, t));
            }
            else if (type == typeof(Color))
            {
                t.Value = EditorGUI.ColorField(rect, label, (Color)GetMemberValue(member, t));
            }
            else if (type == typeof(Vector2))
            {
                t.Value = EditorGUI.Vector2Field(rect, label, (Vector2)GetMemberValue(member, t));
            }
            else if (type == typeof(Vector3))
            {
                t.Value = EditorGUI.Vector3Field(rect, label, (Vector3)GetMemberValue(member, t));
            }
            else if (type == typeof(Vector4))
            {
                t.Value = EditorGUI.Vector4Field(rect, label, (Vector4)GetMemberValue(member, t));
            }
            else if (type == typeof(RangeOfFloats))
            {
                RenderRangeOfFloats(rect, t, member, clamp);
            }
            else if (type == typeof(RangeOfIntegers))
            {
                RenderRangeOfInts(rect, t, member, clamp);
            }
            else if (type.IsEnum)
            {
                t.Value = EditorGUI.EnumPopup(rect, label, (System.Enum)GetMemberValue(member, t));
            }
            else
            {
                EditorGUI.LabelField(rect, "Unsupported field type " + type);
            }
        }
        protected void DrawValue(Rect rect, SerializedProperty Target)
        {
            if (Target.propertyType != SerializedPropertyType.Generic)
            {
                Color backgroundColor = GUI.backgroundColor;
                GUI.backgroundColor *= new Color(1f, 1f, 1f, 0.5f);
                switch (Target.propertyType)
                {
                case SerializedPropertyType.Float:
                    GUI.Box(rect, Target.floatValue.ToString(), Drawer.valueBoxStyle);
                    break;

                case SerializedPropertyType.Integer:
                    GUI.Box(rect, Target.intValue.ToString(), Drawer.valueBoxStyle);
                    break;

                case SerializedPropertyType.String:
                    GUI.Box(rect, new GUIContent("\"" + Target.stringValue + "\"", Target.stringValue), Drawer.valueBoxStyle);
                    break;

                case SerializedPropertyType.Boolean:
                    GUI.Box(rect, Target.boolValue.ToString(), Drawer.valueBoxStyle);
                    break;

                case SerializedPropertyType.Color:
                {
                    using (var disable = new EditorGUI.DisabledGroupScope(true))
                    {
                        var n = rect.height - EditorGUIUtility.singleLineHeight;
                        rect.height = EditorGUIUtility.singleLineHeight;
                        rect.y     += n * 0.5f;
                        EditorGUI.ColorField(rect, Target.colorValue);
                    }
                    break;
                }

                case SerializedPropertyType.Enum:
                    if (Target.enumValueIndex < Target.enumDisplayNames.Length && Target.enumValueIndex >= 0)
                    {
                        GUI.Box(rect, Target.enumDisplayNames[Target.enumValueIndex].ToString(), Drawer.valueBoxStyle);
                    }
                    else
                    {
                        GUI.Box(rect, new GUIContent(Drawer.miniErrorIcon, "The enum value set on prefab is missing, please check the component."), Drawer.valueBoxStyle);
                    }
                    break;

                case SerializedPropertyType.LayerMask:
                    GUI.Box(rect, Target.intValue.ToString(), Drawer.valueBoxStyle);
                    break;

                case SerializedPropertyType.Vector3:
                    GUI.Box(rect, Target.vector3Value.ToString(), Drawer.valueBoxStyle);
                    break;

                case SerializedPropertyType.Vector2:
                    GUI.Box(rect, Target.vector2Value.ToString(), Drawer.valueBoxStyle);
                    break;

                case SerializedPropertyType.ObjectReference:
                    using (var disable = new EditorGUI.DisabledGroupScope(true))
                    {
                        var n = rect.height - EditorGUIUtility.singleLineHeight;
                        rect.height = EditorGUIUtility.singleLineHeight;
                        rect.y     += n * 0.5f;
                        if (Target.objectReferenceValue)
                        {
                            EditorGUI.ObjectField(rect, Target.objectReferenceValue, typeof(UnityEngine.Object), false);
                        }
                        else
                        {
                            GUI.Box(rect, new GUIContent("null", "null"), Drawer.valueBoxStyle);
                        }
                    }
                    break;

                default:
                    GUI.Box(rect, new GUIContent(Target.propertyType.ToString(), Target.propertyType.ToString()), Drawer.valueBoxStyle);
                    break;
                }
                GUI.backgroundColor = backgroundColor;
            }
        }
Beispiel #25
0
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, prop);

            position.height = base.GetPropertyHeight(prop, label);
            Rect basePosition = position;

            int originalIndentLevel = EditorGUI.indentLevel;

            if (!readonlyPropertiesAttribute.HideVariable)
            {
                EditorGUI.indentLevel = 0;
                EditorGUI.PropertyField(position, prop);
            }
            else
            {
                basePosition.y -= position.height;
            }

            for (int i = 0; i < propertyInfos.Count; ++i)
            {
                basePosition.y += position.height;
                position        = basePosition;

                Rect boxPos = position;
                boxPos.width = Screen.width;
                boxPos.x     = 0;
                if (propertyTypes[i] == typeof(Rect) || propertyTypes[i] == typeof(Vector4) || (propertyTypes[i] == typeof(Vector3) && Screen.width < 335))
                {
                    boxPos.height = 2 * EditorGUIUtility.singleLineHeight;
                }
                boxPos.height += 1;
                GUI.color      = Color.gray;
                EditorGUI.HelpBox(boxPos, "", MessageType.None);
                GUI.color = Color.white;

                Rect lockPosition = position;
                lockPosition.width = lockPosition.height;
                lockPosition.y    += 1;
                lockPosition.x    -= 13;
                GUI.Toggle(lockPosition, true, "", "IN LockButton");

                if (propertyTypes[i] != typeof(Quaternion) && propertyTypes[i] != typeof(Vector2) && propertyTypes[i] != typeof(Vector3) && propertyTypes[i] != typeof(Vector4))
                {
                    position = EditorGUI.PrefixLabel(position, EditorGUIUtility.GetControlID(FocusType.Passive), new GUIContent(FormatLikeInspector(readonlyPropertiesAttribute.Properties[i])));
                }

                if (propertyTypes[i] == typeof(AnimationCurve))
                {
                    EditorGUI.CurveField(position, (AnimationCurve)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null));
                }
                else if (propertyTypes[i] == typeof(bool))
                {
                    EditorGUI.Toggle(position, (bool)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null));
                }
                else if (propertyTypes[i] == typeof(Bounds))
                {
                    EditorGUI.BoundsField(position, (Bounds)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null));
                }
                else if (propertyTypes[i] == typeof(Color))
                {
                    EditorGUI.ColorField(position, (Color)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null));
                }
                else if (propertyTypes[i] == typeof(float))
                {
                    EditorGUI.SelectableLabel(position, ((float)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null)).ToString());
                }
                else if (propertyTypes[i] == typeof(int))
                {
                    EditorGUI.SelectableLabel(position, ((int)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null)).ToString());
                }
                else if (propertyTypes[i] == typeof(Quaternion))
                {
                    EditorGUI.Vector3Field(position, new GUIContent(FormatLikeInspector(readonlyPropertiesAttribute.Properties[i])), ((Quaternion)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null)).eulerAngles);
                }
                else if (propertyTypes[i] == typeof(Rect))
                {
                    EditorGUI.RectField(position, (Rect)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null));
                    basePosition.y += position.height;
                }
                else if (propertyTypes[i] == typeof(string))
                {
                    EditorGUI.SelectableLabel(position, (string)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null));
                }
                else if (propertyTypes[i] == typeof(Vector2))
                {
                    EditorGUI.Vector2Field(position, new GUIContent(FormatLikeInspector(readonlyPropertiesAttribute.Properties[i])), (Vector2)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null));
                }
                else if (propertyTypes[i] == typeof(Vector3))
                {
                    EditorGUI.Vector3Field(position, new GUIContent(FormatLikeInspector(readonlyPropertiesAttribute.Properties[i])), (Vector3)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null));
                    if (Screen.width < 335)
                    {
                        basePosition.y += position.height;
                    }
                }
                else if (propertyTypes[i] == typeof(Vector4))
                {
                    EditorGUI.Vector4Field(position, FormatLikeInspector(readonlyPropertiesAttribute.Properties[i]), (Vector4)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null));
                    basePosition.y += position.height;
                }
                else if (typeof(UnityEngine.Object).IsAssignableFrom(propertyTypes[i]))
                {
                    EditorGUI.ObjectField(position, (UnityEngine.Object)propertyInfos[i].GetGetMethod().Invoke(prop.serializedObject.targetObject, null), propertyTypes[i], true);
                }
            }

            EditorGUI.indentLevel = originalIndentLevel;

            EditorGUI.EndProperty();
        }
Beispiel #26
0
    private static void PropertyFieldExtendedValue(Rect position, SerializedPropertyX property, GUIContent label = null, GUIStyle style = null)
    {
        Type type = property.type;

        if (type.IsSubclassOf(typeof(UnityEngine.Object)))
        {
            property.Value = EditorGUI.ObjectField(position, label, (UnityEngine.Object)property.Value, type, true);
        }
        else if (type.IsArray)
        {
            if (property.Value == null)
            {
                property.Value = Array.CreateInstance(type.GetElementType(), 1);
            }
            //int ctrlId = GUIUtility.GetControlID(FocusType.Keyboard);
            property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
            if (property.isExpanded)
            {
                position.y      += 16f;
                position.height -= 16f;
                EditorGUI.indentLevel++;
                Array array     = (Array)property.Value;
                int   length    = array.Length;
                int   newLength = 0;
                z = EditorGUI.IntField(position, new GUIContent("Size"), z);

                if (newLength < 0)
                {
                    newLength = 0;
                }
                if (length != newLength)
                {
                    var newArray = Array.CreateInstance(type.GetElementType(), newLength);
                    for (int i = 0; i < newLength; i++)
                    {
                        if (i == array.Length)
                        {
                            break;
                        }
                        newArray.SetValue(array.GetValue(i), i);
                    }
                    array.CopyTo(newArray, 0);
                    array = newArray;
                }
                position.y      += 16f;
                position.height -= 16f;

                Type elementType = array.GetType().GetElementType();

                for (int i = 0; i < array.Length; i++)
                {
                    if (array.GetValue(i) == null)
                    {
                        array.SetValue(CreateInstance(elementType), i);
                    }
                    //array.SetValue(PropertyFieldExtendedValue(position, elementType, array.GetValue(i), new GUIContent("Element " + i), null), i);
                    //position.y += 48f; //needs to be += getheight
                }
                EditorGUI.indentLevel--;
            }
        }
        else if (type.IsEnum)
        {
            if (style == null)
            {
                style = EditorStyles.popup;                //todo unity default is popup field
            }
            property.Value = EditorGUI.EnumMaskField(position, label, (Enum)property.Value, style);
        }
        else if (type == typeof(Color))
        {
            property.Value = EditorGUI.ColorField(position, label, (Color)property.Value);
        }
        else if (type == typeof(Bounds))
        {
            Bounds b = (Bounds)property.Value;
            position    = EditorGUI.PrefixLabel(position, label);
            position.x -= 48f;
            EditorGUI.LabelField(position, new GUIContent("Center:"));
            position.x     += 53f;
            position.width -= 5f;
            b.center        = EditorGUI.Vector3Field(position, GUIContent.none, b.center);
            position.y     += 16f;
            position.x     -= 53f;
            EditorGUI.LabelField(position, new GUIContent("Extents:"));
            position.x    += 53f;
            b.extents      = EditorGUI.Vector3Field(position, GUIContent.none, b.extents);
            property.Value = b;
        }
        else if (type == typeof(AnimationCurve))
        {
            if (property.Value == null)
            {
                property.Value = new AnimationCurve();
            }
            position.width = 200f;
            property.Value = EditorGUI.CurveField(position, label, (AnimationCurve)property.Value);
        }
        else if (type == typeof(double))
        {
            if (style == null)
            {
                style = EditorStyles.numberField;
            }
            property.Value = EditorGUI.DoubleField(position, label, (double)property.Value, style);
        }
        else if (type == typeof(float))
        {
            if (style == null)
            {
                style = EditorStyles.numberField;
            }
            property.Value = EditorGUI.FloatField(position, label, (float)property.Value, style);
        }
        else if (type == typeof(int))
        {
            if (style == null)
            {
                style = EditorStyles.numberField;
            }
            property.Value = EditorGUI.IntField(position, label, (int)property.Value, style);
        }
        else if (type == typeof(long))
        {
            if (style == null)
            {
                style = EditorStyles.numberField;
            }
            property.Value = EditorGUI.LongField(position, label, (long)property.Value, style);
        }
        else if (type == typeof(Rect))
        {
            property.Value = EditorGUI.RectField(position, label, (Rect)property.Value);
        }
        else if (type == typeof(bool))
        {
            if (style == null)
            {
                style = EditorStyles.toggle;
            }
            property.Value = EditorGUI.Toggle(position, label, (bool)property.Value, style);
        }
        else if (type == typeof(Vector2))
        {
            property.Value = EditorGUI.Vector2Field(position, label, (Vector2)property.Value);
        }
        else if (type == typeof(Vector3))
        {
            property.Value = EditorGUI.Vector3Field(position, label, (Vector3)property.Value);
        }
        else if (type == typeof(Vector4))
        {
            property.Value = EditorGUI.Vector4Field(position, label.text, (Vector4)property.Value);
        }
        else if (type == typeof(string))
        {
            if (style == null)
            {
                style = EditorStyles.textField;
            }
            property.Value = EditorGUI.TextField(position, label, (string)property.Value, style);
        }
        else
        {
            property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
            if (property.isExpanded)
            {
                EditorGUI.indentLevel++;
                position.y      += 16f;
                position.height -= 16f;
                for (int i = 0; i < property.ChildCount; i++)
                {
                    SerializedPropertyX child = property.GetChildAt(i);
                    PropertyField(position, child);
                    float propHeight = EditorGUIUtilityX.GetHeight(child, child.label, child.isExpanded);
                    position.y      += propHeight;
                    position.height -= propHeight;
                }
                EditorGUI.indentLevel--;
            }
        }
    }
Beispiel #27
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var nameProperty  = property.GetMemberProperty <TweenShaderProperty>(p => p.name);
            var typeProperty  = property.GetMemberProperty <TweenShaderProperty>(p => p.type);
            var curveProperty = property.GetMemberProperty <TweenShaderProperty>(p => p.curve);
            var fromProperty  = property.GetMemberProperty <TweenShaderProperty>(p => p.from);
            var toProperty    = property.GetMemberProperty <TweenShaderProperty>(p => p.to);

            var mainRow  = position.Row(0);
            var fromRect = position.Row(1).Right(-FromToPadding);
            var toRect   = position.Row(2).Right(-FromToPadding);

            Rect nameRect, typeRect, curveRect;

            nameRect = mainRow.Right(CurveWidth, out curveRect).Right(TypeWidth, out typeRect);

            var tweenShader    = property.serializedObject.targetObject as TweenShader;
            var targetRenderer = tweenShader.targetRenderer;

            if (targetRenderer == null)
            {
                nameProperty.stringValue    = EditorGUI.TextField(nameRect, nameProperty.stringValue);
                typeProperty.enumValueIndex = EditorGUI.Popup(typeRect, typeProperty.enumValueIndex, typeProperty.enumDisplayNames);
            }
            else
            {
                TweenShaderPropertiesCache cache;
                if (!propertiesCache.TryGetValue(targetRenderer, out cache))
                {
                    cache = new TweenShaderPropertiesCache();
                    propertiesCache.Add(targetRenderer, cache);
                }

                cache.UpdateProperties(tweenShader);

                int index = System.Array.IndexOf(cache.propertyNameOptions, nameProperty.stringValue);
                index = EditorGUI.Popup(nameRect, index, cache.propertyNameOptions);

                nameProperty.stringValue    = cache.properties[index].name;
                typeProperty.enumValueIndex = ( int )cache.properties[index].type;

                EditorGUI.BeginDisabledGroup(true);
                EditorGUI.Popup(typeRect, typeProperty.enumValueIndex, typeProperty.enumDisplayNames);
                EditorGUI.EndDisabledGroup();
            }

            curveProperty.animationCurveValue = EditorGUI.CurveField(curveRect, curveProperty.animationCurveValue);

            EditorHelper.BeginChangeLabelWidth(FromToLabelWidth);

            Vector4 fromVector = fromProperty.vector4Value;
            Vector4 toVector   = toProperty.vector4Value;

            var type = (TweenShaderProperty.Type)typeProperty.enumValueIndex;

            switch (type)
            {
            case TweenShaderProperty.Type.Float:
                fromVector.x = EditorGUI.FloatField(fromRect, fromLabel, fromVector.x);
                fromProperty.vector4Value = fromVector;

                toVector.x = EditorGUI.FloatField(toRect, toLabel, toVector.x);
                toProperty.vector4Value = toVector;

                break;

            case TweenShaderProperty.Type.Vector:
                float labelWidth = EditorGUIUtility.labelWidth;

                EditorGUI.LabelField(fromRect.Left(labelWidth), fromLabel);
                fromVector = EditorGUI.Vector4Field(fromRect.Right(-labelWidth).Row(-1), "", fromVector);
                fromProperty.vector4Value = fromVector;

                EditorGUI.LabelField(toRect.Left(labelWidth), toLabel);
                toVector = EditorGUI.Vector4Field(toRect.Right(-labelWidth).Row(-1), "", toVector);
                toProperty.vector4Value = toVector;

                break;

            case TweenShaderProperty.Type.Color:
                fromVector = EditorGUI.ColorField(fromRect, fromLabel, fromVector, true, true, true, colorPickerConfig);
                fromProperty.vector4Value = fromVector;

                toVector = EditorGUI.ColorField(toRect, toLabel, toVector, true, true, true, colorPickerConfig);
                toProperty.vector4Value = toVector;

                break;
            }

            EditorHelper.EndChangeLabelWidth();

            property.serializedObject.ApplyModifiedProperties();
        }
        ///////////////////////////   OnGUI   /////////////////////////////////////////////
        protected override void OnGUI(Rect position, GUIContent label)
        {
            // Start block
#if UNITY_2021_1_OR_NEWER
            BeginBlock(metadata, position);
#else
            BeginBlock(metadata, position, GUIContent.none);
#endif
            if (!initialised)
            {
                UpdatePalette();                // Probably not required with Scriptable **************
            }
            xWidth      = position.width;
            xFieldRatio = (xWidth < 336 ? ((335 - xWidth) / xFieldDivision) + xFieldDivision / 10f : 0) + ((xWidth - 335) / xFieldDivision);
            unit        = (CommentNode)metadata.value;

            // Initially copy settings to selected unit if Copy is Active
            if (copyACTIVE && copyUnit != null)
            {
                if (copyColor)
                {
                    unit.color = copyUnit.color;
                }
                if (copyFontColor)
                {
                    unit.fontColor = copyUnit.fontColor;
                }
                if (copyFontSize)
                {
                    unit.fontSize = copyUnit.fontSize;
                }
                if (copyFontStyle)
                {
                    unit.fontBold = copyUnit.fontBold; unit.fontItalic = copyUnit.fontItalic; unit.hasOutline = copyUnit.hasOutline;
                }
                if (copyLockToFontColor)
                {
                    unit.fontColorize = copyUnit.fontColorize;
                }
                if (copyLockToPalette)
                {
                    unit.lockedToPalette = copyUnit.lockedToPalette; unit.paletteSelection = copyUnit.paletteSelection; unit.customPalette = copyUnit.customPalette;
                }
                if (copyMaxWidth)
                {
                    unit.maxWidth = copyUnit.maxWidth; unit.autoWidth = copyUnit.autoWidth;
                }
                if (copyTitle)
                {
                    unit.title = copyUnit.title; unit.hasTitle = copyUnit.hasTitle;
                }
                if (copyContent)
                {
                    unit.comment = copyUnit.comment;
                }
            }


            ///////////////////////////   Section - Color Palette   /////////////////////////////////////////////

            // Header
            GUI.contentColor = new Color(1, 1, 0.6f);
            GUI.Label(GUIRect(xMargin: xIndentA, yMargin: position.y, w: xIndentC, h: 20), "Color Palette", sectionGUI);

            // View custom palette?
            ToggleButtonColor(unit.customPalette, alwaysVisible: true);
            if (GUI.Button(GUIRect(xMargin: xIndentC, w: 60, h: 18), "Custom", buttonGUI))
            {
                unit.customPalette = !unit.customPalette;
            }
            if (unit.lockedToPalette)
            {
                unit.paletteSelection.palette = unit.customPalette ? 1 : 0;
            }

            // Copy current unit colors to a custom color
            ToggleButtonColor(customAddColor, red: true);
            if (unit.customPalette)
            {
                if (GUI.Button(GUIRect(right: 65), "Add Color", buttonGUI))
                {
                    unit.customPalette = true; customAddColor = !customAddColor;
                }
            }

            // Separator
            EditorGUI.DrawRect(GUIRect(xMargin: xIndentA, down: 20, w: xWidth, h: 1), new Color(0.5f, 0.5f, 0.5f, 1));

            // Palette initial start point
            GUIRect(xMargin: xIndentB, down: 10, w: xWidth / columns - 1f, h: 30);

            // Draw palette
            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < columns; col++)
                {
                    GUI.backgroundColor = colorPalette[unit.customPalette ? 1 : 0, row, col];
                    GUI.contentColor    = fontPalette[(unit.customPalette ? 2 : unit.fontColorize ? 1 : 0), row, col];
                    if (GUI.Button(GUIRect(x: (xWidth - xIndentA) / columns * col), "Aa"))
                    {
                        // If adding custom color, set selected custom palette color to current color
                        if (customAddColor)
                        {
                            customAddColor = unit.fontColorize = false;

                            colorPalette[1, row, col] = unit.color * 3f;
                            fontPalette[2, row, col]  = unit.fontColor;
                        }
                        // Else set current unit color to selected palette color
                        else
                        {
                            unit.color     = GUI.backgroundColor / 3f;
                            unit.fontColor = GUI.contentColor;
                        }
                        unit.paletteSelection = (unit.customPalette ? 1 : 0, row, col);
                    }

                    // If lockToPalette draw selection box
                    if (row == unit.paletteSelection.row && col == unit.paletteSelection.col && unit.lockedToPalette)
                    {
                        GUI.DrawTexture(GUIRect(x: (xWidth - xIndentA) / columns * col, w: xWidth / columns - 1f), Texture2D.whiteTexture, ScaleMode.ScaleAndCrop, false, 0, fontPalette[1, row, col], 3f, 6f);
                    }
                }
                GUIRect(down: 30);
            }
            ResetGUI();

            // Lock to palette?
            ToggleButtonColor(unit.lockedToPalette);
            if (GUI.Button(GUIRect(x: (xWidth - xIndentA) / columns * 0, down: 10, w: xWidth / columns * 2f - 4, h: 18), "Lock Palette", buttonGUI))
            {
                unit.lockedToPalette = !unit.lockedToPalette;
            }
            ResetGUI();

            // + Draw current color picker
            var tempColor = unit.color;
            ToggleButtonColor(customAddColor, red: true);
            unit.color = EditorGUI.ColorField(GUIRect(x: (xWidth - xIndentA) / columns * 2), new GUIContent(""), unit.color, true, false, false);
            ResetGUI();
            if (unit.customPalette && unit.lockedToPalette && tempColor != unit.color)
            {
                colorPalette[1, unit.paletteSelection.row, unit.paletteSelection.col] = (unit.color * 3f).WithAlpha(3f);
            }

            // + Draw current font color
            tempColor = unit.fontColor;
            GUI.Label(GUIRect(x: (xWidth - xIndentA) / columns * 5f - 25, w: 23), "Aa", commentGUI);
            ToggleButtonColor(customAddColor, red: true);
            unit.fontColor = EditorGUI.ColorField(GUIRect(x: (xWidth - xIndentA) / columns * 5, w: xWidth / columns * 2f - 4f), new GUIContent(""), unit.fontColor, true, false, false);
            ResetGUI();
            if (unit.customPalette && unit.lockedToPalette && tempColor != unit.fontColor)
            {
                fontPalette[2, unit.paletteSelection.row, unit.paletteSelection.col] = unit.fontColor;                                                                           //
            }
            // + Colorize font?
            ToggleButtonColor(unit.fontColorize);
            if (unit.lockedToPalette && !unit.customPalette)
            {
                if (GUI.Button(GUIRect(x: (xWidth - xIndentA) / columns * 7, w: xWidth / columns * 2f - 2), "Colorize", buttonGUI))
                {
                    unit.fontColorize = !unit.fontColorize; UpdatePalette();
                }
            }
            ResetGUI();

            ///////////////////////////   Section - Settings   /////////////////////////////////////////////

            // Header
            GUI.contentColor = new Color(1, 1, 0.6f);
            GUI.Label(GUIRect(xMargin: xIndentA, down: 33, w: xIndentC, h: 20), "Settings", sectionGUI);
            EditorGUI.DrawRect(GUIRect(down: 20, w: xWidth, h: 1), new Color(0.5f, 0.5f, 0.5f, 1));
            ResetGUI();

            // Color Spread
            tempFloat = style.colorSpread;
            GUI.Label(GUIRect(xMargin: 0, x: xIndentB, down: 10, w: xIndentC, h: 18), "Color Spread", inspectorGUI);
            style.colorSpread = Mathf.Clamp(EditorGUI.FloatField(GUIRect(x: xIndentC + xFieldOffset - xFieldRatio, w: xIndentC + xFieldWidth + xFieldRatio - 5), " ", style.colorSpread * 10f, titleGUI) / 10f, 0f, 3f);
            if (style.colorSpread != tempFloat)
            {
                UpdatePalette();
            }

            // + Toggle greyscale?
            ToggleButtonColor(style.greyScale);
            if (GUI.Button(GUIRect(right: xIndentC + 50, w: 40), "Grey", buttonGUI))
            {
                style.greyScale = !style.greyScale; UpdatePalette();
            }
            ResetGUI();

            // + 3 palette presets
            if (GUI.Button(GUIRect(right: 42), "Mars", buttonGUI))
            {
                style.colorSpread = 1.5f; style.colorOffset = 0f; UpdatePalette();
            }
            if (GUI.Button(GUIRect(right: 42), "Pastel", buttonGUI))
            {
                style.colorSpread = 1.5f; style.colorOffset = 0.4f; UpdatePalette();
            }
            if (GUI.Button(GUIRect(right: 42), "Vivid", buttonGUI))
            {
                style.colorSpread = 2.5f; style.colorOffset = 0.4f; UpdatePalette();
            }

            // Color Contrast
            tempFloat = style.colorHeight;
            GUI.Label(GUIRect(xMargin: 0, x: xIndentB, down: 22, w: xIndentC), "Color Offset", inspectorGUI);
            style.colorHeight = Mathf.Clamp(EditorGUI.FloatField(GUIRect(x: xIndentC + xFieldOffset - xFieldRatio, w: xIndentC + xFieldWidth + xFieldRatio - 5), " ", style.colorHeight * 10f, titleGUI) / 10f, 0.6f, 9.8f);
            if (style.colorHeight != tempFloat)
            {
                UpdatePalette();
            }

            // Color Offset
            tempFloat = style.colorOffset;
            GUI.Label(GUIRect(xMargin: 0, x: xIndentB, down: 22, w: xIndentC), "Color Height", inspectorGUI);
            style.colorOffset = Mathf.Clamp(EditorGUI.FloatField(GUIRect(x: xIndentC + xFieldOffset - xFieldRatio, w: xIndentC + xFieldWidth + xFieldRatio - 5), " ", style.colorOffset * 10f, titleGUI) / 10f, 0f, 1.5f);
            if (style.colorOffset != tempFloat)
            {
                UpdatePalette();
            }

            // Font Size + Bold? Italic? Outline? Centre?
            GUI.Label(GUIRect(x: xIndentB, down: 22, w: xIndentC), "Font Size", inspectorGUI);
            unit.fontSize = EditorGUI.IntField(GUIRect(right: xIndentC, x: xFieldOffset - xFieldRatio, w: xIndentC + xFieldWidth + xFieldRatio - 5), " ", unit.fontSize, titleGUI);

            ToggleButtonColor(unit.fontBold);
            if (GUI.Button(GUIRect(right: 50, w: 40), "Bold", buttonGUI))
            {
                unit.fontBold = !unit.fontBold;
            }

            ToggleButtonColor(unit.fontItalic);
            if (GUI.Button(GUIRect(right: 42), "Italic", buttonGUI))
            {
                unit.fontItalic = !unit.fontItalic;
            }

            ToggleButtonColor(unit.hasOutline);
            if (GUI.Button(GUIRect(right: 42), "Outline", buttonGUI))
            {
                unit.hasOutline = !unit.hasOutline;
            }

            ToggleButtonColor(unit.alignCentre);
            if (GUI.Button(GUIRect(right: 42), "Centre", buttonGUI))
            {
                unit.alignCentre = !unit.alignCentre;
            }
            ResetGUI();

            // Max Width + Auto?
            GUI.Label(GUIRect(xMargin: 0, x: xIndentB, down: 22, w: xIndentC), "Max Width", inspectorGUI);
            unit.maxWidth = EditorGUI.IntField(GUIRect(x: xIndentC + xFieldOffset - xFieldRatio, w: xIndentC + xFieldWidth + xFieldRatio - 5), " ", unit.maxWidth, titleGUI);
            ToggleButtonColor(unit.autoWidth);
            if (GUI.Button(GUIRect(x: xIndentC + 50, w: 40), "Auto", buttonGUI))
            {
                unit.autoWidth = !unit.autoWidth;
            }
            ResetGUI();

            // Comment Title
            GUI.Label(GUIRect(x: xIndentB, down: 33), "Title", inspectorGUI);
            unit.hasTitle = GUI.Toggle(GUIRect(x: xIndentC, w: 20), unit.hasTitle, "");
            if (unit.hasTitle)
            {
                unit.title = GUI.TextField(GUIRect(x: xIndentC + 20, w: xWidth - xIndentC - 10, h: 16), unit.title, titleGUI);
            }

            // Comment Contents
            var textHeight = commentGUI.CalcHeight(new GUIContent(unit.comment), xWidth - xIndentC + 10);
            GUI.Label(GUIRect(x: xIndentB, down: 22, w: xWidth, h: 18), "Comment", inspectorGUI);
            unit.comment = GUI.TextArea(GUIRect(x: xIndentC, w: xWidth - xIndentC + 10, h: textHeight + 2), unit.comment, commentGUI);


            ///////////////////////////   Section - Copy   /////////////////////////////////////////////

            // Header
            GUI.contentColor = new Color(1, 1, 0.6f);
            GUI.Label(GUIRect(right: xIndentA, down: textHeight + 2 - 18 + 33, w: xWidth, h: 20), "Copy Painter", sectionGUI);
            EditorGUI.DrawRect(GUIRect(down: 20, h: 1), new Color(0.5f, 0.5f, 0.5f, 1));
            ResetGUI();

            // Toggle Copy ACTIVE + show active at the top of inspector
            ToggleButtonColor(copyACTIVE, red: true);
            if (GUI.Button(GUIRect(xMargin: 0, x: xIndentB, down: 10, w: xIndentC - xIndentB - 10, h: 18), "ACTIVE", buttonGUI))
            {
                copyACTIVE = !copyACTIVE;
            }
            if (copyACTIVE)
            {
                if (GUI.Button(GUIRect(x: xIndentA + xWidth - 100, y: position.y - yCurrent, w: 100), "COPY ACTIVE", buttonGUI))
                {
                    copyACTIVE = !copyACTIVE;
                }
            }
            ResetGUI();

            // If Copy is ACTIVE show other buttons
            if (copyACTIVE)
            {
                // All
                ToggleButtonColor(copyAll, alwaysVisible: true);
                if (GUI.Button(GUIRect(right: xIndentC, w: 50), "All", buttonGUI))
                {
                    copyAll    = !copyAll;
                    copyCOLORS = copyLOCK = copyFONT = copyColor = copyFontColor = copyLockToPalette = copyLockToFontColor = copyFontSize = copyFontStyle = copyMaxWidth = copyTitle = copyContent = copyAll;
                }

                // Colors
                ToggleButtonColor(copyCOLORS, alwaysVisible: true);
                if (GUI.Button(GUIRect(down: 22), "Colors", buttonGUI))
                {
                    copyCOLORS = !copyCOLORS;
                    copyColor  = copyFontColor = copyCOLORS;
                }

                ToggleButtonColor(copyColor);
                if (GUI.Button(GUIRect(right: 55), "Box", buttonGUI))
                {
                    copyColor = !copyColor;
                }

                ToggleButtonColor(copyFontColor);
                if (GUI.Button(GUIRect(right: 55), "Font", buttonGUI))
                {
                    copyFontColor = !copyFontColor;
                }

                // Locks
                ToggleButtonColor(copyLOCK, alwaysVisible: true);
                if (GUI.Button(GUIRect(xMargin: xIndentC, down: 22), "Locks", buttonGUI))
                {
                    copyLOCK          = !copyLOCK;
                    copyLockToPalette = copyLockToFontColor = copyLOCK;
                }

                ToggleButtonColor(copyLockToPalette);
                if (GUI.Button(GUIRect(right: 55), "Palette", buttonGUI))
                {
                    copyLockToPalette = !copyLockToPalette;
                }

                ToggleButtonColor(copyLockToFontColor);
                if (GUI.Button(GUIRect(right: 55), "Colorize", buttonGUI))
                {
                    copyLockToFontColor = !copyLockToFontColor;
                }

                // Font
                ToggleButtonColor(copyFONT, alwaysVisible: true);
                if (GUI.Button(GUIRect(xMargin: xIndentC, down: 22), "Font", buttonGUI))
                {
                    copyFONT     = !copyFONT;
                    copyFontSize = copyFontStyle = copyMaxWidth = copyFONT;
                }

                ToggleButtonColor(copyFontSize);
                if (GUI.Button(GUIRect(right: 55), "Size", buttonGUI))
                {
                    copyFontSize = !copyFontSize;
                }

                ToggleButtonColor(copyFontStyle);
                if (GUI.Button(GUIRect(right: 55), "Style", buttonGUI))
                {
                    copyFontStyle = !copyFontStyle;
                }

                ToggleButtonColor(copyMaxWidth);
                if (GUI.Button(GUIRect(right: 55), "Width", buttonGUI))
                {
                    copyMaxWidth = !copyMaxWidth;
                }

                // Text
                ToggleButtonColor(copyTEXT, alwaysVisible: true);
                if (GUI.Button(GUIRect(xMargin: xIndentC, down: 22), "Text", buttonGUI))
                {
                    copyTEXT = !copyTEXT;
                }

                ToggleButtonColor(copyTitle);
                if (GUI.Button(GUIRect(right: 55), "Title", buttonGUI))
                {
                    copyTitle = !copyTitle;
                }

                ToggleButtonColor(copyContent);
                if (GUI.Button(GUIRect(right: 55), "Content", buttonGUI))
                {
                    copyContent = !copyContent;
                }

                copyCOLORS = copyColor && copyFontColor;
                copyLOCK   = copyLockToPalette && copyLockToFontColor;
                copyFONT   = copyFontSize && copyFontStyle && copyMaxWidth;
                copyTEXT   = copyTitle && copyContent;
                copyAll    = copyCOLORS && copyLOCK && copyFONT && copyTEXT;
            }
            ResetGUI();

            // Copy the current unit to copyUnit, to use during copy
            copyUnit = unit;

            // EndBlock, record Undo, and write back unit details to the actual unit
            if (EndBlock(metadata))
            {
                metadata.RecordUndo();
                metadata.value = unit;
            }
        }
        /// <summary>
        /// Shows an object field editor for object types that do no derive from UnityEngine.Object.
        /// </summary>
        /// <typeparam Name="T">Type of the object to modify.</typeparam>
        /// <param Name="position">The region to show the UI.</param>
        /// <param Name="label">Label to show.</param>
        /// <param Name="value">Current value to show.</param>
        /// <param Name="allowSceneObjects">Whether scene objects should be allowed in the set of field choices.</param>
        /// <returns>The new value.</returns>
        public static T ObjectField <T>(Rect position, GUIContent label, T value, bool allowSceneObjects)
        {
            object objValue = value;

            Type valueType = objValue.GetType();

            if (valueType == typeof(Bounds))
            {
                objValue = EditorGUI.BoundsField(position, label, (Bounds)objValue);
            }
            else if (valueType == typeof(Color))
            {
                objValue = EditorGUI.ColorField(position, label, (Color)objValue);
            }
            else if (valueType == typeof(Material))
            {
                objValue = EditorGUI.ObjectField(position, (Material)objValue, typeof(Material), allowSceneObjects);
            }
            else if (valueType == typeof(AnimationCurve))
            {
                objValue = EditorGUI.CurveField(position, label, (AnimationCurve)objValue);
            }
            else if (valueType == typeof(float))
            {
                objValue = EditorGUI.FloatField(position, label, (float)objValue);
            }
            else if (valueType == typeof(int))
            {
                objValue = EditorGUI.IntField(position, label, (int)objValue);
            }
            else if (valueType == typeof(LayerMask))
            {
                objValue = EditorGUI.MaskField(position, label, (LayerMask)objValue, LayerMaskExtensions.LayerMaskNames);
            }
            else if (valueType.IsEnum)
            {
                if (valueType.GetCustomAttributes(typeof(FlagsAttribute), true).Length > 0)
                {
#if UNITY_2017_3_OR_NEWER
                    objValue = EditorGUI.EnumFlagsField(position, label, (Enum)objValue);
#else
                    objValue = EditorGUI.EnumMaskField(position, label, (Enum)objValue);
#endif
                }
                else
                {
                    objValue = EditorGUI.EnumPopup(position, label, (Enum)objValue);
                }
            }
            else if (valueType == typeof(Rect))
            {
                objValue = EditorGUI.RectField(position, label, (Rect)objValue);
            }
            else if (valueType == typeof(string))
            {
                objValue = EditorGUI.TextField(position, label, (string)objValue);
            }
            else if (valueType == typeof(Vector2))
            {
                objValue = EditorGUI.Vector2Field(position, new GUIContent(), (Vector2)objValue);
            }
            else if (valueType == typeof(Vector3))
            {
                objValue = EditorGUI.Vector3Field(position, new GUIContent(), (Vector3)objValue);
            }
            else if (valueType == typeof(Vector4))
            {
                if (label.image != null)
                {
                    throw new ArgumentException("Images not supported for labels of Vector4 fields.", "label");
                }

                if (!string.IsNullOrEmpty(label.tooltip))
                {
                    throw new ArgumentException("Tool-tips not supported for labels of Vector4 fields.", "label");
                }

                objValue = EditorGUI.Vector4Field(position, label.text, (Vector4)objValue);
            }
            else if (Equals(objValue, typeof(SceneAsset)))
            {
                objValue = EditorGUI.ObjectField(position, (SceneAsset)objValue, typeof(SceneAsset), allowSceneObjects);
            }
            else if (objValue is UnityEngine.Object)
            {
                objValue = EditorGUI.ObjectField(position, label, (UnityEngine.Object)objValue, valueType, allowSceneObjects);
            }
            else
            {
                throw new ArgumentException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "Unimplemented value type: {0}.",
                              valueType),
                          "value");
            }

            return((T)objValue);
        }
Beispiel #30
0
        void OnModuleWindowCB(int id)
        {
            // something happened in the meantime?
            if (id >= Modules.Count || mModuleCount != Modules.Count)
            {
                return;
            }
            CGModule mod = Modules[id];

            //if (LMB && Sel.SelectedModules.Count<=1)
            if (EV.type == EventType.MouseUp && !Sel.SelectedModules.Contains(mod))
            {
                Sel.Select(Modules[id]);
            }

            Rect winRect = mod.Properties.Dimensions;

            // Draw Title Buttons
            // Enabled
            EditorGUI.BeginChangeCheck();
            mod.Active = GUI.Toggle(new Rect(2, 2, 16, 16), mod.Active, "");
            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(Generator);
            }

            //Edit Title & Color
            if (editTitleModule == mod)
            {
                GUI.SetNextControlName("editTitle" + id);
                mod.ModuleName = GUI.TextField(new Rect(30, 5, winRect.width - 120, 16), mod.ModuleName);
                mod.Properties.BackgroundColor = EditorGUI.ColorField(new Rect(winRect.width - 70, 5, 32, 16), mod.Properties.BackgroundColor);
            }


            if (GUI.Button(new Rect(winRect.width - 32, 6, 16, 16), new GUIContent(CurvyStyles.EditTexture, "Rename"), CurvyStyles.BorderlessButton))
            {
                editTitleModule = mod;
                Sel.Select(mod);
                EditorGUI.FocusTextInControl("editTitle" + id);
            }

            // Help
            if (GUI.Button(new Rect(winRect.width - 16, 6, 16, 16), new GUIContent(CurvyStyles.HelpTexture, "Help"), CurvyStyles.BorderlessButton))
            {
                var url = DTUtility.GetHelpUrl(mod);
                if (!string.IsNullOrEmpty(url))
                {
                    Application.OpenURL(url);
                }
            }



            // Check errors
            if (mod.CircularReferenceError)
            {
                EditorGUILayout.HelpBox("Circular Reference", MessageType.Error);
            }
            // Draw Slots
            DTGUI.PushColor(mod.Properties.BackgroundColor.SkinAwareColor(true));
            EditorGUILayout.BeginVertical(CurvyStyles.ModuleWindowSlotBackground);
            DTGUI.PopColor();
            OnModuleWindowSlotGUI(mod);
            EditorGUILayout.EndVertical();

            var ed = GetModuleEditor(mod);

            if (ed && ed.target != null)
            {
                if (EditorGUILayout.BeginFadeGroup(mShowDebug.faded))
                {
                    ed.OnInspectorDebugGUIINTERNAL(Repaint);
                }
                EditorGUILayout.EndFadeGroup();

                // Draw Module Options

                mod.Properties.Expanded.valueChanged.RemoveListener(Repaint);
                mod.Properties.Expanded.valueChanged.AddListener(Repaint);

                if (!CurvyProject.Instance.CGAutoModuleDetails)
                {
                    mod.Properties.Expanded.target = GUILayout.Toggle(mod.Properties.Expanded.target, new GUIContent(mod.Properties.Expanded.target ? CurvyStyles.CollapseTexture : CurvyStyles.ExpandTexture, "Show Details"), EditorStyles.toolbarButton);
                }

                // === Module Details ===
                // Handle Auto-Folding
                if (DTGUI.IsLayout && CurvyProject.Instance.CGAutoModuleDetails)
                {
                    mod.Properties.Expanded.target = (mod == Sel.SelectedModule);
                }

                if (EditorGUILayout.BeginFadeGroup(mod.Properties.Expanded.faded))
                {
                    EditorGUIUtility.labelWidth = (mod.Properties.LabelWidth);
                    // Draw Inspectors using Modules Background color
                    DTGUI.PushColor(ed.Target.Properties.BackgroundColor.SkinAwareColor(true));
                    EditorGUILayout.BeginVertical(CurvyStyles.ModuleWindowBackground);
                    DTGUI.PopColor();

                    ed.RenderGUI(true);
                    if (ed.NeedRepaint)
                    {
                        mDoRepaint = true;
                    }
                    GUILayout.Space(2);
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndFadeGroup();
            }

            // Make it dragable
            GUI.DragWindow(new Rect(0, 0, winRect.width, CurvyStyles.ModuleWindowTitleHeight));
        }