示例#1
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        SeparationLine.Horizontal();
        EditorGUILayout.LabelField(target.name, K10GuiStyles.bigBoldCenterStyle, GUILayout.Height(28));
        SeparationLine.Horizontal();

        EditorGUILayout.PropertyField(_alsoLogToConsole);

        SeparationLine.Horizontal();
        EditorGUILayout.LabelField("Custom log", K10GuiStyles.boldCenterStyle, GUILayout.Height(28));
        EditorGUILayout.BeginHorizontal();
        GUILayout.TextField(SystemInfo.deviceName);
        GUILayout.TextField(System.DateTime.Now.ToStringOrNull());
        EditorGUILayout.EndHorizontal();
        textToAdd = GUILayout.TextArea(textToAdd);
        if (GUILayout.Button("Add Custom Log"))
        {
            var log = (EditorLog)target;
            log.Add(textToAdd);
        }
        SeparationLine.Horizontal();

        for (int i = _log.arraySize - 1; i >= 0; i--)
        {
            var line     = _log.GetArrayElementAtIndex(i);
            var dateTime = line.FindPropertyRelative("_dateTime");
            var date     = System.DateTime.FromFileTimeUtc(dateTime.longValue);
            var author   = line.FindPropertyRelative("_author");
            var message  = line.FindPropertyRelative("_message").stringValue;

            EditorGUILayout.BeginHorizontal();
            GUILayout.TextField(author.stringValue);
            GUILayout.TextField(date.ToStringOrNull());
            if (IconButton.Layout("minus", '-', "Remove log line", K10GuiStyles.CYAN_TINT_COLOR))
            {
                _log.DeleteArrayElementAtIndex(i);
            }
            EditorGUILayout.EndHorizontal();
            GUILayout.TextArea(message);
        }

        serializedObject.ApplyModifiedProperties();
    }
    public override void OnInspectorGUI()
    {
        var collection = (BaseHashedSOCollection)target;
        int size       = collection.Count;

        var count = 0;

        for (int i = 0; i < size; i++)
        {
            var entry = collection.GetElementBase(i);
            if (entry == null)
            {
                continue;
            }
            count++;
        }

        SeparationLine.Horizontal();
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField($"{_title} ({count})", K10GuiStyles.bigBoldCenterStyle, GUILayout.Height(28));
        if (IconButton.Layout("log", 32, 'L', "Show modification log", K10GuiStyles.CYAN_TINT_COLOR))
        {
            var asset = collection.Editor_Log;
            // if( asset != null )
            // {
            //  EditorUtility.FocusProjectWindow();
            //  Selection.activeObject = asset;
            // }
        }
        EditorGUILayout.EndHorizontal();
        SeparationLine.Horizontal();

        var edit = (IHashedSOCollectionEditor)collection;

        EditorGUILayout.BeginVertical();
        var lastValid = -1;

        for (int i = 0; i < size; i++)
        {
            var entry = collection.GetElementBase(i) as IHashedSO;
            if (entry == null)
            {
                if (lastValid + 1 == i)
                {
                    GUILayout.Space(5);
                }
                continue;
            }
            lastValid = i;
            EditorGUILayout.BeginHorizontal();
            var hasConflict = (entry.HashID < 0 || entry.HashID != i);
            if (hasConflict)
            {
                GuiColorManager.New(Color.red);
            }
            if (IconButton.Layout("objective", 's'))
            {
                Selection.SetActiveObjectWithContext(entry as Object, entry as Object);
            }
            EditorGUILayout.LabelField("[" + i.ToString() + "]", GUILayout.Width(30f));

            var tryResolve = hasConflict && GUILayout.Button("!!CONFLICT!!");

            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.ObjectField(entry as Object, collection.GetElementType(), false);
            EditorGUI.EndDisabledGroup();

            if (hasConflict)
            {
                GuiColorManager.Revert();
            }

            EditorGUILayout.EndHorizontal();

            if (tryResolve)
            {
                edit.TryResolveConflict(i);
            }
        }
        EditorGUILayout.EndVertical();
        if (GUILayout.Button("Check Consistency"))
        {
            edit.EditorCheckConsistency();
        }
        if (edit.EditorCanChangeIDsToOptimizeSpace && GUILayout.Button("Optimize"))
        {
            edit.EditorTryOptimize();
        }

        GuiColorManager.New(Color.red);
        if (GUILayout.Button("!DANGER! Enforce HashIDs"))
        {
            edit.Editor_HACK_EnforceHashIDs();
        }
        GuiColorManager.Revert();
    }
示例#3
0
    public override void OnInspectorGUI()
    {
        bool changed = false;

        serializedObject.Update();
        _target = (UiSkinManager)target;
        Event ev = Event.current;

        HashSet <string> _codes = new HashSet <string>();

        var defsProp = serializedObject.FindProperty("_colorDefinitions");

        //var defs = _target.SkinDefinitions;
        //if( defsProp.arraySize == 0 )
        //	return;

        if (_folds == null)
        {
            _folds = new List <bool>();
        }
        while (_folds.Count > defsProp.arraySize)
        {
            _folds.RemoveAt(_folds.Count - 1);
        }
        while (_folds.Count < defsProp.arraySize)
        {
            _folds.Add(false);
        }

        for (int i = 0; i < defsProp.arraySize; i++)
        {
            SeparationLine.Horizontal();
            var def = defsProp.GetArrayElementAtIndex(i);

            var codeName = def.FindPropertyRelative("_code");
            var valid    = !_codes.Contains(codeName.stringValue);
            var color    = valid ? Color.white : Color.red;
            GuiColorManager.New(color);

            EditorGUILayout.BeginHorizontal();
            _folds[i] = EditorGUILayout.Foldout(_folds[i], (valid ? "" : "!UNUSED! ") + codeName.stringValue, K10GuiStyles.bigFoldStyle);


            var fxOrderProp = def.FindPropertyRelative("_effectOrder");
            var instance    = _target.SkinDefinitions[i];
            for (int e = 0; e < instance.FxCount; e++)
            {
                var fx = instance.GetFxAt(e);
                DrawFxIcon(fx);
            }

            bool canUp = i > 0;
            GuiColorManager.New((canUp) ? color : Color.gray);
            if (GUILayout.Button("↑", GUILayout.MaxWidth(15)) && canUp)
            {
                SwapSkins(i, i - 1);
            }
            GuiColorManager.Revert();

            bool canDown = i < defsProp.arraySize - 1;
            GuiColorManager.New((canDown) ? color : Color.gray);
            if (GUILayout.Button("↓", GUILayout.MaxWidth(15)) && canDown)
            {
                SwapSkins(i, i + 1);
            }
            GuiColorManager.Revert();

            GuiColorManager.New(new Color(.6f, .1f, .1f, 1));
            if (GUILayout.Button("X", GUILayout.MaxWidth(20)))
            {
                K10EditorGUIUtils.RemoveItemFromArray(defsProp, i);
                i--;
                GuiColorManager.Revert();
                GuiColorManager.Revert();
                EditorGUILayout.EndHorizontal();
                continue;
            }

            GuiColorManager.Revert();
            EditorGUILayout.EndHorizontal();

            if (_folds[i])
            {
                SeparationLine.Horizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Codename", K10GuiStyles.smallboldStyle, GUILayout.Width(75));
                codeName.stringValue = EditorGUILayout.TextField(codeName.stringValue, K10GuiStyles.smalltextFieldStyle, GUILayout.Height(18));
                _codes.Add(codeName.stringValue);
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                //GUILayout.Label( "Color", K10EditorGUIUtils._smallboldStyle, GUILayout.Width( 40 ) );
                ColorPicker.Layout(def.FindPropertyRelative("_color"));
                //def.Color = EditorGUILayout.ColorField( def.Color );
                //GUILayout.Label( "Font", K10EditorGUIUtils._smallboldStyle, GUILayout.Width( 35 ) );
                var fontProp = def.FindPropertyRelative("_font");
                fontProp.objectReferenceValue = (Font)EditorGUILayout.ObjectField(fontProp.objectReferenceValue, typeof(Font), false);
                EditorGUILayout.EndHorizontal();


                SeparationLine.Horizontal();
                GUILayout.Label("Effects", K10GuiStyles.titleStyle);
                SeparationLine.Horizontal();

                var shadowProp   = def.FindPropertyRelative("_shadow");
                var outlineProp  = def.FindPropertyRelative("_outline");
                var gradientProp = def.FindPropertyRelative("_gradient");

                var sid = UiSkinDefinition.GetID <UiShadowEffect>();
                var oid = UiSkinDefinition.GetID <UiOutlineEffect>();
                var gid = UiSkinDefinition.GetID <UiGradientEffect>();

                EditorGUILayout.BeginHorizontal();
                //GUILayout.FlexibleSpace();
                //EditorGUILayout.BeginVertical();
                ButtonAddEffect(fxOrderProp, sid, "Shadow");
                ButtonAddEffect(fxOrderProp, oid, "Outline");
                ButtonAddEffect(fxOrderProp, gid, "Gradient");
                //EditorGUILayout.EndVertical();
                //GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();

                if (fxOrderProp.arraySize > 0)
                {
                    SeparationLine.Horizontal();
                    GUILayout.Label("Edit Effects", K10GuiStyles.titleStyle);
                    for (int e = 0; e < fxOrderProp.arraySize; e++)
                    {
                        SeparationLine.Horizontal();
                        if (sid == fxOrderProp.GetArrayElementAtIndex(e).intValue)
                        {
                            EditShadow(shadowProp, fxOrderProp, e);
                        }
                        else if (oid == fxOrderProp.GetArrayElementAtIndex(e).intValue)
                        {
                            EditOutline(outlineProp, fxOrderProp, e);
                        }
                        else if (gid == fxOrderProp.GetArrayElementAtIndex(e).intValue)
                        {
                            EditGradient(gradientProp, fxOrderProp, e);
                        }
                    }
                }
            }

            SeparationLine.Horizontal();
            EditorGUILayout.Space();
            GuiColorManager.Revert();
        }

        if (GUILayout.Button("Add New Skin Definition", K10GuiStyles.buttonStyle, GUILayout.Height(30)))
        {
            defsProp.arraySize++;
        }

        serializedObject.ApplyModifiedProperties();

        changed = true;
        if (changed)
        {
            UpdateInstances();
        }
    }
示例#4
0
    public override void OnInspectorGUI()
    {
        if (_labelStyle == null)
        {
            _labelStyle = new GUIStyle(EditorStyles.label)
            {
                alignment = TextAnchor.MiddleLeft
            }
        }
        ;

        if (IconButton.Layout("tool" + (_unityDefault ? "on" : "off"), 16, 'T', "Unity default Transform", Color.yellow))
        {
            _unityDefault = !_unityDefault;
        }

        if (_unityDefault)
        {
            base.OnInspectorGUI();
            return;
        }

        Transform t = (Transform)target;

        Vector3 initialposition    = t.localPosition;
        Vector3 initialeulerAngles = t.localEulerAngles;
        Vector3 initialscale       = t.localScale;

        Vector3 position    = t.localPosition;
        Vector3 eulerAngles = t.localEulerAngles;
        Vector3 scale       = t.localScale;

        GUILayoutOption[] opt = new GUILayoutOption[] { /*GUILayout.MinWidth(80.0f),*/ GUILayout.MaxHeight(20.0f) };

        if (targets.Length > 1)
        {
            GUI.color = Color.Lerp(Color.yellow, Color.white, .8f);
        }

        EditorGUILayout.BeginHorizontal(opt);
        bool resetPos = IconButton.Layout("zero", 16, '0', "Reset position to zero", Color.white);

//		bool resetPos = GUILayout.Button( "0 ", GUILayout.Width( 18f ) );
        position = EditorGUILayout.Vector3Field("", position);
//		_positionAdvanced = GUILayout.Toggle( _positionAdvanced, "", GUILayout.Width( 20f ) );
        if (IconButton.Layout("tool" + (_positionAdvanced ? "on" : "off"), 16, 'T', "Advanced position tools", Color.yellow))
        {
            _positionAdvanced = !_positionAdvanced;
        }
        EditorGUILayout.EndHorizontal();

        var color = GUI.color;

        GUI.color = Color.Lerp(Color.blue, color, .9f);
        bool rndPX = false, rndPY = false, rndPZ = false, drop = false, offset = false;

        if (_positionAdvanced)
        {
            SeparationLine.Horizontal();

            EditorGUILayout.BeginHorizontal(opt);
            GUILayout.Label("Offset", _labelStyle, GUILayout.Width(40f));
            _offsetPos = EditorGUILayout.Vector3Field("", _offsetPos);
            offset     = GUILayout.Button("Move", GUILayout.Width(40f));
            EditorGUILayout.EndHorizontal();

            SeparationLine.Horizontal();

            EditorGUILayout.BeginHorizontal(opt);
            GUILayout.Label("Randomize", _labelStyle, GUILayout.Width(70f));
            rndPX = GUILayout.Button("X?", GUILayout.Width(25f));
            rndPY = GUILayout.Button("Y?", GUILayout.Width(25f));
            rndPZ = GUILayout.Button("Z?", GUILayout.Width(25f));
            var all = GUILayout.Button("All?", GUILayout.Width(35f));

            GUILayout.Space(30);
            drop = GUILayout.Button("Drop", GUILayout.Width(40f));

            if (all)
            {
                rndPX = rndPY = rndPZ = true;
            }

            EditorGUILayout.EndHorizontal();
//			SeparationLine.Horizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("min", GUILayout.Width(30f));
            _minPos = EditorGUILayout.Vector3Field("", _minPos);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("max", GUILayout.Width(30f));
            _maxPos = EditorGUILayout.Vector3Field("", _maxPos);
            //			EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndHorizontal();
            SeparationLine.Horizontal();
        }
        GUI.color = color;

        EditorGUILayout.BeginHorizontal(opt);
        bool resetRot = IconButton.Layout("zero", 16, '0', "Reset rotation to zero", Color.white);

//		bool resetRot = GUILayout.Button( "0 ", GUILayout.Width( 18f ) );
        eulerAngles = EditorGUILayout.Vector3Field("", eulerAngles);
//		_rotationAdvanced = GUILayout.Toggle( _rotationAdvanced, "", GUILayout.Width( 20f ) );
        if (IconButton.Layout("tool" + (_rotationAdvanced ? "on" : "off"), 16, 'T', "Advanced rotation tools", Color.yellow))
        {
            _rotationAdvanced = !_rotationAdvanced;
        }
        EditorGUILayout.EndHorizontal();

        color     = GUI.color;
        GUI.color = Color.Lerp(Color.blue, color, .9f);
        bool rndRX = false, rndRY = false, rndRZ = false;
        bool faceCenter = false;
        bool awayCenter = false;

        if (_rotationAdvanced)
        {
            SeparationLine.Horizontal();
            EditorGUILayout.BeginHorizontal(opt);
            EditorGUILayout.BeginVertical();
            GUILayout.Label("Randomize", GUILayout.Width(70f));
            EditorGUILayout.EndVertical();
            rndRX = GUILayout.Button("X?", GUILayout.Width(25f));
            rndRY = GUILayout.Button("Y?", GUILayout.Width(25f));
            rndRZ = GUILayout.Button("Z?", GUILayout.Width(25f));
            var all = GUILayout.Button("All?", GUILayout.Width(35f));
            faceCenter = GUILayout.Button("Face?", GUILayout.Width(45f));
            awayCenter = GUILayout.Button("Away?", GUILayout.Width(50f));

            if (all)
            {
                rndRX = rndRY = rndRZ = true;
            }

            EditorGUILayout.EndHorizontal();
//			SeparationLine.Horizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("min", GUILayout.Width(30f));
            _minRot = EditorGUILayout.Vector3Field("", _minRot);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("max", GUILayout.Width(30f));
            _maxRot = EditorGUILayout.Vector3Field("", _maxRot);
            EditorGUILayout.EndHorizontal();
            SeparationLine.Horizontal();
        }
        GUI.color = color;

        EditorGUILayout.BeginHorizontal(opt);
        bool resetScl = IconButton.Layout("one", 16, '1', "Reset scale to one", Color.white);

//		bool resetScl = GUILayout.Button( "1 ", GUILayout.Width( 18f ) );
        scale = EditorGUILayout.Vector3Field("", scale);
//		_scaleAdvanced = GUILayout.Toggle( _scaleAdvanced, "", GUILayout.Width( 20f ) );
        if (IconButton.Layout("tool" + (_scaleAdvanced ? "on" : "off"), 16, 'T', "Advanced scale tools", Color.yellow))
        {
            _scaleAdvanced = !_scaleAdvanced;
        }
        EditorGUILayout.EndHorizontal();

        color     = GUI.color;
        GUI.color = Color.Lerp(Color.blue, color, .9f);
        bool rndSX = false, rndSY = false, rndSZ = false, bakeScl = false;

        if (_scaleAdvanced)
        {
            SeparationLine.Horizontal();
            EditorGUILayout.BeginHorizontal(opt);
            //GUILayout.Space( 45f );
            GUILayout.Label("Randomize", GUILayout.Width(70f));
            rndSX = GUILayout.Button("X?", GUILayout.Width(25f));
            rndSY = GUILayout.Button("Y?", GUILayout.Width(25f));
            rndSZ = GUILayout.Button("Z?", GUILayout.Width(25f));
            var all = GUILayout.Button("All?", GUILayout.Width(35f));
            if (all)
            {
                rndSX = rndSY = rndSZ = true;
            }

            _sameRangeValue = GUILayout.Toggle(_sameRangeValue, "Same", GUILayout.Width(50f));
            bakeScl         = GUILayout.Button("Bake", GUILayout.Width(45f));
            EditorGUILayout.EndHorizontal();
//			SeparationLine.Horizontal();

            if (_sameRangeValue)
            {
                var w = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 30;
                _minBaseScl = EditorGUILayout.FloatField("min", _minBaseScl);
                _maxBaseScl = EditorGUILayout.FloatField("max", _maxBaseScl);
                EditorGUIUtility.labelWidth = w;
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("min", GUILayout.Width(30f));
                _minScl = EditorGUILayout.Vector3Field("", _minScl);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("max", GUILayout.Width(30f));
                _maxScl = EditorGUILayout.Vector3Field("", _maxScl);
                EditorGUILayout.EndHorizontal();
            }
            SeparationLine.Horizontal();
        }
        GUI.color = color;

        if (GUI.changed)
        {
            foreach (Transform trans in serializedObject.targetObjects)
            {
                var so = new SerializedObject(trans);
                //var current = (Transform)currentTarget;

                so.Update();
                SerializedProperty posProp = so.FindProperty("m_LocalPosition");
                SerializedProperty rotProp = so.FindProperty("m_LocalRotation");
                SerializedProperty sclProp = so.FindProperty("m_LocalScale");

                //Undo.RegisterUndo( current, "Transform Change" );

                var localPosition = posProp.vector3Value;
                if (!Mathf.Approximately(initialposition.x, position.x))
                {
                    localPosition.x = position.x;
                }
                if (!Mathf.Approximately(initialposition.y, position.y))
                {
                    localPosition.y = position.y;
                }
                if (!Mathf.Approximately(initialposition.z, position.z))
                {
                    localPosition.z = position.z;
                }

                var localEulerAngles = rotProp.quaternionValue.eulerAngles;
                if (!Mathf.Approximately(initialeulerAngles.x, eulerAngles.x))
                {
                    localEulerAngles.x = eulerAngles.x;
                }
                if (!Mathf.Approximately(initialeulerAngles.y, eulerAngles.y))
                {
                    localEulerAngles.y = eulerAngles.y;
                }
                if (!Mathf.Approximately(initialeulerAngles.z, eulerAngles.z))
                {
                    localEulerAngles.z = eulerAngles.z;
                }

                var localScale = sclProp.vector3Value;
                if (!Mathf.Approximately(initialscale.x, scale.x))
                {
                    localScale.x = scale.x;
                }
                if (!Mathf.Approximately(initialscale.y, scale.y))
                {
                    localScale.y = scale.y;
                }
                if (!Mathf.Approximately(initialscale.z, scale.z))
                {
                    localScale.z = scale.z;
                }

                if (resetPos)
                {
                    localPosition = Vector3.zero;
                }
                if (rndPX)
                {
                    localPosition.x = Random.Range(_minPos.x, _maxPos.x);
                }
                if (rndPY)
                {
                    localPosition.y = Random.Range(_minPos.y, _maxPos.y);
                }
                if (rndPZ)
                {
                    localPosition.z = Random.Range(_minPos.z, _maxPos.z);
                }


                if (offset)
                {
                    localPosition += _offsetPos;
                }

                if (resetRot)
                {
                    localEulerAngles = Vector3.zero;
                }

                if (faceCenter)
                {
                    var pos = trans.position;
                    localEulerAngles.y = Mathf.Atan2(pos.x, pos.z) * Mathf.Rad2Deg - (trans.parent != null ? trans.parent.eulerAngles.y : 0);
                }

                if (awayCenter)
                {
                    var pos = trans.position;
                    localEulerAngles.y = Mathf.Atan2(pos.x, pos.z) * Mathf.Rad2Deg - 180 - (trans.parent != null ? trans.parent.eulerAngles.y : 0);
                }

                if (rndRX)
                {
                    localEulerAngles.x = Random.Range(_minRot.x, _maxRot.x);
                }
                if (rndRY)
                {
                    localEulerAngles.y = Random.Range(_minRot.y, _maxRot.y);
                }
                if (rndRZ)
                {
                    localEulerAngles.z = Random.Range(_minRot.z, _maxRot.z);
                }

                var baseScale = Random.Range(_minBaseScl, _maxBaseScl);
                if (resetScl)
                {
                    localScale = Vector3.one;
                }
                if (rndSX)
                {
                    localScale.x = _sameRangeValue ? baseScale : Random.Range(_minScl.x, _maxScl.x);
                }
                if (rndSY)
                {
                    localScale.y = _sameRangeValue ? baseScale : Random.Range(_minScl.y, _maxScl.y);
                }
                if (rndSZ)
                {
                    localScale.z = _sameRangeValue ? baseScale : Random.Range(_minScl.z, _maxScl.z);
                }


                if (drop)
                {
                    Vector3    pPos = (trans.parent != null) ? trans.parent.position : Vector3.zero;
                    var        pos  = trans.position;
                    RaycastHit hit;
                    if (Physics.Raycast(pos, Vector3.down, out hit, float.MaxValue))
                    {
                        pos           = hit.point - pPos;
                        localPosition = pos;
                    }
                }

                posProp.vector3Value    = FixIfNaN(localPosition);
                rotProp.quaternionValue = Quaternion.Euler(FixIfNaN(localEulerAngles));
                sclProp.vector3Value    = FixIfNaN(localScale);

                if (bakeScl)
                {
                    BakeScale(so);
                }

                so.ApplyModifiedProperties();
            }
        }
    }