public override void OnInspectorGUI() { ButterfliesArea area = (ButterfliesArea)target; EditorGUI.BeginChangeCheck(); area.Count = EditorGUILayout.IntField("Count", area.Count); SerializedProperty prop = serializedObject.FindProperty("prefabs"); SerializedProperty speed = serializedObject.FindProperty("speed"); EditorGUILayout.PropertyField(prop, true); EditorGUILayout.PropertyField(speed, true); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); Undo.RecordObject(target, "Changed field"); } EditorUtility.SetDirty(target); if (GUILayout.Button("Spawn")) { area.SpawnButterflies(); } if (GUILayout.Button("Remove all")) { area.RemoveButterflies(); } if (!Application.isPlaying) { EditorSceneManager.MarkAllScenesDirty(); } }
internal void Initialize(ButterfliesArea butterfliesArea) { startPosition = transform.position; startRotation = transform.rotation; height = startPosition.y; this.butterfliesArea = butterfliesArea; state = BStates.Sit; timer = UnityEngine.Random.Range(0, 10f); animator = GetComponent <Animator>(); AnimatorStateInfo animatorState = animator.GetCurrentAnimatorStateInfo(0);//could replace 0 by any other animation layer index animator.Play(animatorState.fullPathHash, -1, UnityEngine.Random.Range(0f, 1f)); }