Beispiel #1
0
        public static void Iso2DObjectField(SerializedObject _Iso2DSerializedObject)
        {
            _Iso2DSerializedObject.Update();

            SerializedProperty vScaler  = _Iso2DSerializedObject.FindProperty("localScale");
            SerializedProperty vRotator = _Iso2DSerializedObject.FindProperty("localRotation");

            Iso2DObject    _Iso2D      = (Iso2DObject)_Iso2DSerializedObject.targetObject;
            IsoTile        _parentTile = _Iso2D.GetComponentInParent <IsoTile>();
            SpriteRenderer sprr        = _Iso2D.GetComponent <SpriteRenderer>();

            //_Iso2D._Type = (Iso2DObject.Type) EditorGUILayout.EnumPopup("Type", _Iso2D._Type);

            bool bUpdateScale           = false;
            bool bToggledApplyGlobalPPU = false;

            EditorGUI.indentLevel = 0;
            bUpdateScale          = Undo_Iso2DSpriteField(_Iso2D, Color.cyan);

            if (sprr.sprite != null)
            {
                EditorGUILayout.LabelField("Type : " + _Iso2D._Type);

                float iWidth = EditorGUIUtility.currentViewWidth / 2 - 4;

                EditorGUILayout.BeginHorizontal();
                using (new EditorGUILayout.VerticalScope(
                           GUILayout.MaxWidth(iWidth)))
                {
                    GUILayout.Space(5);

                    Iso2DObjectEditor.Max_Slider = Mathf.Max(new float[] { 1f, vScaler.vector3Value.x, vScaler.vector3Value.y,
                                                                           EditorGUILayout.FloatField("Cap of Scale Slider", Iso2DObjectEditor.Max_Slider) });

                    vScaler.vector3Value = Vector3Slider(vScaler.vector3Value, Vector3.one, "[Scale]",
                                                         -Iso2DObjectEditor.Max_Slider * Vector3.one, Iso2DObjectEditor.Max_Slider * Vector3.one, iWidth);
                    // vScaler.vector3Value = EditorGUILayout.Vector3Field("",vScaler.vector3Value, GUILayout.MaxWidth(iWidth));
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        EditorGUILayout.LabelField("Flip", GUILayout.MaxWidth(iWidth * 0.3f));
                        if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.MaxWidth(iWidth * 0.3f)))
                        {
                            vScaler.vector3Value = Vector3.Scale(vScaler.vector3Value, new Vector3(-1, 1, 1));
                        }
                        if (GUILayout.Button("Y", EditorStyles.miniButton, GUILayout.MaxWidth(iWidth * 0.3f)))
                        {
                            vScaler.vector3Value = Vector3.Scale(vScaler.vector3Value, new Vector3(1, -1, 1));
                        }
                    }

                    if (!IsoMap.IsNull)
                    {
                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.ToggleLeft(
                            string.Format("Use Global PPU Scale(x{0:0.00})", _Iso2D.PPURefScale),
                            _Iso2D.bApplyPPUScale, GUILayout.MaxWidth(iWidth));
                        bUpdateScale |= bToggledApplyGlobalPPU = EditorGUI.EndChangeCheck();

                        EditorGUI.indentLevel++;
                        EditorGUILayout.HelpBox("Global PPU Scale = Source PPU / Ref PPU", MessageType.None);
                        EditorGUILayout.LabelField(
                            "Image Source PPU " + sprr.sprite.pixelsPerUnit,
                            GUILayout.MaxWidth(iWidth));
                        EditorGUILayout.LabelField(
                            "IsoMap Reference PPU " + IsoMap.instance.ReferencePPU,
                            GUILayout.MaxWidth(iWidth));
                        EditorGUI.indentLevel--;
                        EditorGUILayout.Separator();
                    }

                    Util.CustomEditorGUI.NewParagraph("[Rotation]");
                    EditorGUILayout.LabelField("Tile local rotation adjustment", GUILayout.MaxWidth(iWidth));
                    vRotator.vector3Value = EditorGUILayout.Vector3Field("", vRotator.vector3Value, GUILayout.MaxWidth(iWidth));
                    EditorGUILayout.LabelField(
                        string.Format("+ global tile rotation(X {0}, Y {1})",
                                      _Iso2D.IsometricAngle.x, _Iso2D.IsometricAngle.y), GUILayout.MaxWidth(iWidth));
                    EditorGUILayout.Separator();

                    //EditorGUILayout.EndVertical();
                    //GUILayout.EndArea();
                }
                drawPackedTexture(_Iso2D, Mathf.Min(125f, iWidth * 0.75f));
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.HelpBox("There no Sprite.", MessageType.None);
            }


            if (_parentTile != null && _Iso2D.gameObject != _parentTile.gameObject)
            {
                EditorGUILayout.Separator();
                Util.CustomEditorGUI.NewParagraph("[Object Selector]");
                if (_Iso2D.RC != null)
                {
                    Util.CustomEditorGUI.ComSelector <RegularCollider>(_Iso2D.RC, "GO Controller");
                }
                else
                {
                    CustomEditorGUI.ComSelector <SubColliderHelper>(_Iso2D.SC, "GO SubCollider");
                }
                Util.CustomEditorGUI.ComSelector <IsoTile>(_parentTile, "GO IsoTile");
            }

            _Iso2DSerializedObject.ApplyModifiedProperties();

            if (bToggledApplyGlobalPPU)
            {
                _Iso2D.Toggle_ApplyPPUScale();
            }

            if (bUpdateScale)
            {
                _Iso2D.AdjustScale();
            }
        }