コード例 #1
0
    protected virtual void DrawBehaviourPopup(Rect rect)
    {
        Type type        = Target.Behaviour?.GetType();
        int  optionIndex = type == null ? BehaviourOptions.Length - 1 : BehaviourTypes.IndexOf(type);

        rect.height = EditorGUIUtility.singleLineHeight;
        int newIndex = EditorGUI.Popup(rect, optionIndex, BehaviourOptions);

        if (newIndex != optionIndex)
        {
            SwitchBehaviourType(newIndex);
        }

        void SwitchBehaviourType(int typeIndex)
        {
            if (typeIndex >= BehaviourTypes.Count)
            {
                RemoveObject(Target.Behaviour);
                Target.Behaviour = null;
            }
            else
            {
                if (Target.Behaviour != null)
                {
                    RemoveObject(Target.Behaviour);
                }

                PatternBehaviour newInstance = CreateBehaviour(typeIndex);

                Target.Behaviour = newInstance;
                AddObject(newInstance);
            }
        }
    }
コード例 #2
0
 public void InitializeBehaviour(PatternBehaviour behaviourPrefab)
 {
     behaviour         = Instantiate(behaviourPrefab);
     behaviour.Pattern = this;
     behaviour.Initialize();
 }
 public void Initialize(PatternBehaviour behaviour, PatternObject obj)
 {
     _behaviour         = behaviour;
     _behaviour.Pattern = obj;
     _behaviour.Initialize();
 }