Example #1
0
 public static void AddSwitchToGameElement(Switch swt, GameElement gameElement) {
     SpriteRenderer spriteRenderer = gameElement.GetComponent<SpriteRenderer>();
     if (spriteRenderer != null) {
         spriteRenderer.enabled = false;
     }
     bool alreadyAdded = false;
     foreach (GameElement ge in gameElement.GameElements) {
         if (ge == swt) {
             alreadyAdded = true;
             break;
         }
     }
     if (alreadyAdded) {
         return;
     }
     SerializedObject serializedObject = new SerializedObject(gameElement);
     SerializedProperty geProperty = serializedObject.FindProperty("gameElements");
     geProperty.InsertArrayElementAtIndex(geProperty.arraySize);
     SerializedProperty element = geProperty.GetArrayElementAtIndex(geProperty.arraySize - 1);
     element.objectReferenceValue = swt;
     serializedObject.ApplyModifiedProperties();
     Editor connectorEditor = ConnectorEditor.CreateEditor(gameElement);
     connectorEditor.OnInspectorGUI();
 }
Example #2
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        bool isUpdateElementCollidersButtonClicked = GUILayout.Button("Update Element Colliders");

        if (isUpdateElementCollidersButtonClicked)
        {
            ElementCollider[] elementColliders = this.target.GetComponentsInChildren <ElementCollider>(true);
            foreach (ElementCollider elementCollider in elementColliders)
            {
                ElementColliderEditor.UpdateColliders(elementCollider, target.StageNum == 38  ? 0.033f : 0.055f);
            }
        }

        bool isUpdatePullersButtonClicked = GUILayout.Button("Update Pullers/End Pullers");

        if (isUpdatePullersButtonClicked)
        {
            Puller[] pullers = this.target.GetComponentsInChildren <Puller>(true);
            foreach (Puller puller in pullers)
            {
                PullerEditor.UpdatePullers(puller);
            }
        }

        bool isApplyMasksButtonClicked = GUILayout.Button("Apply Masks");

        if (isApplyMasksButtonClicked)
        {
            Puller[] pullers = this.target.GetComponentsInChildren <Puller>(true);
            foreach (Puller puller in pullers)
            {
                PullerEditor.ApplyMask(puller);
            }
        }

        bool isSetPullersButtonClicked = GUILayout.Button("Set Pullers");

        if (isSetPullersButtonClicked)
        {
            Switch[] switches = this.target.GetComponentsInChildren <Switch>(true);
            for (int i = 0; i < 10; i++)
            {
                foreach (Switch swt in switches)
                {
                    swt.LookForPullers();
                }
            }

            GameElement[] gameElements = this.target.GetComponentsInChildren <GameElement>(true);
            foreach (GameElement gameElement in gameElements)
            {
                if (!(gameElement is Switch))
                {
                    gameElement.SetPullers();
                }
            }
        }

        bool isAutoLinkButtonClicked = GUILayout.Button("Link Switches");

        if (isAutoLinkButtonClicked)
        {
            Switch[] switches = this.target.GetComponentsInChildren <Switch>(true);
            foreach (Switch swt in switches)
            {
                SwitchEditor.LinkElements(swt);
            }
        }

        bool isDoubleLinkButtonClicked = GUILayout.Button("Double Link Connectors");

        if (isDoubleLinkButtonClicked)
        {
            Connector[] connectors = this.target.GetComponentsInChildren <Connector>(true);
            foreach (Connector connector in connectors)
            {
                foreach (GameElement ge in connector.GameElements)
                {
                    if (!(ge is Connector))
                    {
                        continue;
                    }
                    bool alreadyAdded = false;
                    foreach (GameElement gameElement in ge.GameElements)
                    {
                        if (gameElement != connector)
                        {
                            continue;
                        }
                        alreadyAdded = true;
                        break;
                    }
                    if (alreadyAdded)
                    {
                        continue;
                    }
                    SerializedObject   serializedObject = new SerializedObject(ge);
                    SerializedProperty geProperty       = serializedObject.FindProperty("gameElements");
                    geProperty.InsertArrayElementAtIndex(geProperty.arraySize);
                    SerializedProperty element = geProperty.GetArrayElementAtIndex(geProperty.arraySize - 1);
                    element.objectReferenceValue = connector;
                    serializedObject.ApplyModifiedProperties();
                    Editor connectorEditor = ConnectorEditor.CreateEditor(ge);
                    connectorEditor.OnInspectorGUI();
                }
            }
        }
    }