示例#1
0
 private void OnEnable()
 {
     if (AdvGame.GetReferences() && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.IsUnity2D())
     {
         SortingMap _target = (SortingMap)target;
         _target.transform.forward = Vector3.down;
     }
 }
示例#2
0
    public override void OnInspectorGUI()
    {
        SortingMap _target = (SortingMap)target;

        EditorGUILayout.BeginVertical("Button");
        _target.mapType     = (SortingMapType)EditorGUILayout.EnumPopup("Affect sprite's:", _target.mapType);
        _target.affectScale = EditorGUILayout.Toggle("Affect Character scale?", _target.affectScale);
        if (_target.affectScale)
        {
            _target.affectSpeed = EditorGUILayout.Toggle("Affect Character speed?", _target.affectSpeed);
            _target.originScale = EditorGUILayout.IntField("Start scale (%):", _target.originScale);
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.Space();

        foreach (SortingArea area in _target.sortingAreas)
        {
            int i = _target.sortingAreas.IndexOf(area);

            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.BeginHorizontal();

            area.color = EditorGUILayout.ColorField(area.color);

            EditorGUILayout.LabelField("Position:", GUILayout.Width(50f));
            area.z = EditorGUILayout.FloatField(area.z, GUILayout.Width(80f));

            if (_target.mapType == SortingMapType.OrderInLayer)
            {
                EditorGUILayout.LabelField("Order:", labelWidth);
                area.order = EditorGUILayout.IntField(area.order);
            }
            else if (_target.mapType == SortingMapType.SortingLayer)
            {
                EditorGUILayout.LabelField("Layer:", labelWidth);
                area.layer = EditorGUILayout.TextField(area.layer);
            }

            if (GUILayout.Button(insertContent, EditorStyles.miniButtonLeft, buttonWidth))
            {
                Undo.RecordObject(_target, "Add area");
                if (i < _target.sortingAreas.Count - 1)
                {
                    _target.sortingAreas.Insert(i + 1, new SortingArea(area, _target.sortingAreas[i + 1]));
                }
                else
                {
                    _target.sortingAreas.Insert(i + 1, new SortingArea(area));
                }
                break;
            }
            if (GUILayout.Button(deleteContent, EditorStyles.miniButtonRight, buttonWidth))
            {
                Undo.RecordObject(_target, "Delete area");
                _target.sortingAreas.Remove(area);
                break;
            }

            EditorGUILayout.EndHorizontal();

            if (_target.affectScale)
            {
                area.scale = EditorGUILayout.IntField("End scale (%):", area.scale);
            }

            EditorGUILayout.EndVertical();
        }

        if (GUILayout.Button("Add area"))
        {
            Undo.RecordObject(_target, "Add area");

            if (_target.sortingAreas.Count > 0)
            {
                SortingArea lastArea = _target.sortingAreas [_target.sortingAreas.Count - 1];
                _target.sortingAreas.Add(new SortingArea(lastArea));
            }
            else
            {
                _target.sortingAreas.Add(new SortingArea(_target.transform.position.z + 1f, 1));
            }
        }

        EditorGUILayout.Space();

        if (AdvGame.GetReferences() && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.IsTopDown())
        {
        }
        else if (AdvGame.GetReferences() && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.IsUnity2D())
        {
        }
        else
        {
            if (GUILayout.Button("Face active camera"))
            {
                Undo.RecordObject(_target, "Face active camera");
                Vector3 forwardVector = Camera.main.transform.forward;
                _target.transform.forward = -forwardVector;
                EditorUtility.SetDirty(_target);
            }
        }

        if (_target.affectScale && _target.sortingAreas.Count > 1)
        {
            if (GUILayout.Button("Interpolate in-between scales"))
            {
                Undo.RecordObject(_target, "Interpolate scales");
                _target.SetInBetweenScales();
                EditorUtility.SetDirty(_target);
            }
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(_target);
        }
    }