示例#1
0
    public static void DrawAddActionSelector(GameObject parent, Action addedActionCallback)
    {
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("Add Action:", GUILayout.ExpandWidth(false));

        Type selectedActionType = null;

        selectedActionType = TriggerGUILayout.DrawActionSelector(selectedActionType);
        if (selectedActionType != null)
        {
            int        ordinal          = GetLastExecutionTime(parent) + 1;
            GameObject actionGameObject = new GameObject(selectedActionType.Name);
            actionGameObject.transform.parent = parent.gameObject.transform;
            EventResponder responder = (EventResponder)actionGameObject.AddComponent(selectedActionType);
            responder.Ordinal = ordinal;
            List <TriggerActionGroupDescriptor> actionGroupDescriptors = responder.GetTriggerActionGroups();
            foreach (TriggerActionGroupDescriptor descriptor in actionGroupDescriptors)
            {
                TriggerActionGroup.CreateActionGroup(descriptor).transform.parent = responder.gameObject.transform;
            }
            addedActionCallback();
        }
        GUILayout.EndHorizontal();
    }
示例#2
0
    public static bool DrawCustomActionInspectorBar(bool expanded, EventResponder responder, out EventResponder newResponder)
    {
        //Event.current.type == EventType.
        EditorGUILayout.BeginHorizontal();

        EditorGUILayoutExt.BeginLabelStyle(12, FontStyle.Bold, new Color(0.45f, 0.45f, 0.45f), null);
        expanded = GUILayout.Button(expanded ? "▼" : "►", GUI.skin.label, GUILayout.ExpandWidth(false)) ? !expanded : expanded;
        bool newEnabled = GUILayout.Toggle(responder.enabled, "", GUILayout.ExpandWidth(false));

        if (newEnabled != responder.enabled)
        {
            responder.enabled = newEnabled;
        }
        EditorGUILayoutExt.BeginLabelStyle(null, null, new Color(1f, 0.72f, 0.72f), null);

        expanded = GUILayout.Button(responder.GetType().Name, GUI.skin.label, GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false)) ? !expanded : expanded;
        GUILayout.FlexibleSpace();

        EditorGUILayoutExt.EndLabelStyle();
        EditorGUILayoutExt.EndLabelStyle();

        if (GUILayout.Button("▲", GUILayout.ExpandWidth(false)))
        {
            MoveOrderableUp(responder);
        }

        if (GUILayout.Button("▼", GUILayout.ExpandWidth(false)))
        {
            MoveOrderableDown(responder);
        }

        Type eventType = TriggerGUILayout.DrawActionSelector(responder.GetType());

        if (eventType != null)
        {
            if (eventType != responder.GetType())
            {
                GameObject responderGameObject = responder.gameObject;
                int        executionTime       = responder.Ordinal;
                GameObject.DestroyImmediate(responder);
                responder                = (EventResponder)responderGameObject.AddComponent(eventType);
                responder.Ordinal        = executionTime;
                responderGameObject.name = responder.GetType().Name;
            }
        }
        else
        {
            IOrderable next;
            int        time = responder.Ordinal + 1;
            while ((next = GetOrderableAtTime(responder.gameObject.transform.parent.gameObject, time)) != null)
            {
                next.Ordinal -= 1;
                time++;
            }
            GameObject.DestroyImmediate(responder.gameObject);
            responder = null;
        }

        EditorGUILayout.EndHorizontal();

        newResponder = responder;
        return(expanded);
    }