using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace CreatureControl {
[CustomEditor(typeof(Creature), true)]
public class Creature_Editor : Editor {
///
/// The creature managed by this editor
///
protected Creature creature;
#region Start
///
/// Enable the creature editor
///
public virtual void OnEnable() {
this.creature = target as Creature;
if (creature.targetRig != null)
creature.animator = creature.targetRig.GetComponent();
// Keep track if anything changed while enabling the creature editor
bool somethingChanged = false;
// if (IsPrefab(this.creature) == false) {
// // Only do this when it is not a prefab
// somethingChanged |= this.creature.CheckTargetRig();
// somethingChanged |= this.creature.CheckModel();
// }
this.creature.targetRig.MatchTo(this.creature, ref somethingChanged);
// As the above functions do not use the serialized object
// We need to manually persist the changes.
if (somethingChanged) {
Debug.Log("something has changed");
EditorUtility.SetDirty(this.creature);
AssetDatabase.SaveAssets();
}
}
///
/// Check if the given creature is a prefab
///
/// The creature to check
/// True when it is a prefab
public static bool IsPrefab(Creature creature) {
PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(creature.gameObject);
return prefabStage != null;
}
#endregion Start
}
}