108 lines
4.1 KiB
C#
108 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
[CustomEditor(typeof(TreeSpotController))]
|
|
public class TreeSpotControllerEditor : Editor
|
|
{
|
|
private TreeSpotController plantSpotController;
|
|
private int itemToPlantIndex = 0, itemToGrowIndex = 0, itemToHealIndex = 0;
|
|
private TreeState plantState = 0;
|
|
|
|
private void OnEnable()
|
|
{
|
|
plantSpotController = (TreeSpotController)target;
|
|
}
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
base.OnInspectorGUI();
|
|
if (plantSpotController.items)
|
|
{
|
|
List<string> resourcesItemNames = new();
|
|
List<bItem> resourceItems = new();
|
|
|
|
List<string> powerScrollItemNames = new();
|
|
List<bItem> powerScrollitems = new();
|
|
|
|
foreach (bItem item in plantSpotController.items.items)
|
|
{
|
|
if (item.type == bItemType.Resources)
|
|
{
|
|
resourcesItemNames.Add(item.name);
|
|
resourceItems.Add(item);
|
|
}
|
|
else if (item.type == bItemType.PowerScroll)
|
|
{
|
|
powerScrollItemNames.Add(item.name);
|
|
powerScrollitems.Add(item);
|
|
}
|
|
}
|
|
|
|
bItem itemToPlant = plantSpotController.itemRequiredToPlant;//(bItem)itemRequiredToPlant.objectReferenceValue;
|
|
bItem itemToGrow = plantSpotController.itemRequiredToGrow;
|
|
bItem itemToHeal = plantSpotController.itemRequiredToHeal;
|
|
if (itemToPlant)
|
|
{
|
|
itemToPlantIndex = resourceItems.FindIndex(item => itemToPlant == item);
|
|
}
|
|
|
|
if (itemToGrow)
|
|
{
|
|
itemToGrowIndex = powerScrollitems.FindIndex(item => itemToGrow == item);
|
|
}
|
|
|
|
if (itemToHeal)
|
|
{
|
|
itemToHealIndex = powerScrollitems.FindIndex(item => itemToHeal == item);
|
|
}
|
|
|
|
GUILayout.Label("Item required to plant", EditorStyles.boldLabel);
|
|
itemToPlantIndex = EditorGUILayout.Popup(itemToPlantIndex, resourcesItemNames.ToArray());
|
|
plantSpotController.itemRequiredToPlant = resourceItems[itemToPlantIndex];
|
|
|
|
GUILayout.Label("Item required to grow", EditorStyles.boldLabel);
|
|
itemToGrowIndex = EditorGUILayout.Popup(itemToGrowIndex, powerScrollItemNames.ToArray());
|
|
plantSpotController.itemRequiredToGrow = powerScrollitems[itemToGrowIndex];
|
|
|
|
GUILayout.Label("Item required to heal", EditorStyles.boldLabel);
|
|
itemToHealIndex = EditorGUILayout.Popup(itemToHealIndex, powerScrollItemNames.ToArray());
|
|
plantSpotController.itemRequiredToHeal = powerScrollitems[itemToHealIndex];
|
|
|
|
GUILayout.Label("Helper Mehtods", EditorStyles.boldLabel);
|
|
|
|
if (GUILayout.Button("Grow Tree"))
|
|
{
|
|
plantSpotController.GrowTree();
|
|
}
|
|
plantState = (TreeState)EditorGUILayout.EnumPopup("Type to set:", plantState);
|
|
|
|
if (GUILayout.Button("Set Tree Instant"))
|
|
{
|
|
plantSpotController.SetTreeStateInstant(plantState);
|
|
}
|
|
|
|
if (GUILayout.Button("Set Tree Animated"))
|
|
{
|
|
plantSpotController.SetTreeStateAnimated(plantState);
|
|
}
|
|
|
|
if (GUILayout.Button("Sicken tree"))
|
|
{
|
|
plantSpotController.SickenTree(10);
|
|
}
|
|
|
|
if (GUILayout.Button("Heal tree"))
|
|
{
|
|
plantSpotController.HealTree();
|
|
}
|
|
EditorUtility.SetDirty(plantSpotController);
|
|
serializedObject.ApplyModifiedProperties();
|
|
}
|
|
}
|
|
}
|
|
} |