コード例 #1
0
ファイル: SuperTab.cs プロジェクト: SimianLogic/ld41
    //Custom classes don't need to create a ProcessNode that doesn't take maybe_recycled_node, since
    //the only way to get here is through the Container/Label/Sprite configs passing it through
    public static void ProcessNode(SuperMetaNode root_node, Transform parent, Dictionary <string, object> node, GameObject maybe_recycled_node)
    {
        string name = (string)node["name"];

        GameObject game_object = maybe_recycled_node;
        SuperTab   tab         = null;

        if (game_object == null)
        {
            game_object = new GameObject();
            tab         = game_object.AddComponent(typeof(SuperTab)) as SuperTab;
        }
        else
        {
            tab = game_object.GetComponent <SuperTab>();
        }

        tab.CreateRectTransform(game_object, node);
        tab.name                 = name;
        tab.rootNode             = root_node;
        tab.cachedMetadata       = node;
        tab.hierarchyDescription = "TAB";

        root_node.controlReferences.Add(new ControlReference(name, tab));

        game_object.transform.SetParent(parent);
        tab.Reset();

        //image nodes don't have children
        if (node.ContainsKey("children"))
        {
            root_node.ProcessChildren(game_object.transform, node["children"] as List <object>);
        }

        //this is cosmetic only... the states won't persist into runtime, but it will hide all but the last
        //found state in the editor so our states dont look like hot garbage
        tab.CreateStates();

        //make sure to call CreateStates in Start() or we won't know what to do!
    }
コード例 #2
0
ファイル: SuperTabEditor.cs プロジェクト: SimianLogic/ld41
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        SuperTab node = (SuperTab)target;

        if (node.currentState == null)
        {
            return;
        }

        if (node.states == null)
        {
            return;
        }

        if (node.states.Count == 0)
        {
            return;
        }


        string[] states = new string[node.states.Count];
        node.states.CopyTo(states);

        var current_choice = Array.IndexOf(states, node.currentState);

        if (current_choice < 0)
        {
            current_choice    = 0;
            node.currentState = states[0];
        }

        // Choose an option from the list
        var choice = EditorGUILayout.Popup("Choose State (Runtime)", current_choice, states);

        // Update the selected option on the underlying instance of SomeClass
        node.currentState = states[choice];
    }