Beispiel #1
0
    public override void OnInspectorGUI()
    {
        MapEvent mapEvent = (MapEvent)target;

        if (GUI.changed)
        {
            mapEvent.SetScreenPositionToMatchTilePosition();
            mapEvent.SetDepth();
        }

        if (!mapEvent.GetComponent <CharaEvent>())
        {
            if (GUILayout.Button("Add Chara Event"))
            {
                GameObject doll = Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>(DollPath));
                doll.name = mapEvent.name + " (doll)";
                GameObjectUtility.SetParentAndAlign(doll, mapEvent.gameObject);
                CharaEvent chara = mapEvent.gameObject.AddComponent <CharaEvent>();
                chara.doll        = doll;
                mapEvent.passable = false;
                Undo.RegisterCreatedObjectUndo(mapEvent, "Create " + doll.name);
                Selection.activeObject = doll;

                // hardcode weirdness
                doll.transform.localPosition = new Vector3(Map.TileSizePx / 2, -Map.TileSizePx, 0.0f);
            }
            GUILayout.Space(25.0f);
        }

        Vector2Int newPosition = EditorGUILayout.Vector2IntField("Tiles position", mapEvent.location);

        if (newPosition != mapEvent.location)
        {
            mapEvent.SetLocation(newPosition);
            EditorUtility.SetDirty(mapEvent);
        }

        Vector2Int newSize = EditorGUILayout.Vector2IntField("Size", mapEvent.size);

        if (newSize != mapEvent.size)
        {
            mapEvent.SetSize(newSize);
            EditorUtility.SetDirty(mapEvent);
        }

        base.OnInspectorGUI();
    }