コード例 #1
0
    private void Awake()
    {
        InitCanvasRaycastingStuff();

        controllerStateMachine = new ExtendedStateMachine <ControllerStates>();

        controllerStateMachine.AddState(ControllerStates.Neutral,
                                        () => {
            controlledSelector.ActivateAndUnpause();
        },
                                        () => {
            EditWaypointMarkerControl();

            if (!ShapeSelectionControl(controlledSelector) &&
                Input.GetMouseButtonDown(1) &&
                NoUIAtScreenPositionExceptCanvas(pointerInfo.pointedPositionScreen, 2))
            {
                controllerStateMachine.CurrentState = ControllerStates.Menu;
            }
        },
                                        () => {
            controlledSelector.Deactivate();
        }
                                        );

        controllerStateMachine.AddState(ControllerStates.Menu,
                                        () => {
            controlledSelector.ActivateAndUnpause();

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Other",
                         pointerInfo.pointedPositionScreen - Vector3.right * 50f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                //controllerStateMachine.CurrentState = ControllerStates.OrderEditing;
            });

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Orders",
                         pointerInfo.pointedPositionScreen + Vector3.right * 50f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                controllerStateMachine.CurrentState = ControllerStates.OrderMenu;
            });

            //PrepareButtonsForMenu(menuCurrentButtons);
        },
                                        () => {
            EditWaypointMarkerControl();

            if (!ShapeSelectionControl(controlledSelector) &&
                Input.GetMouseButtonDown(1) &&
                NoUIAtScreenPositionExceptCanvas(pointerInfo.pointedPositionScreen, 2))
            {
                controllerStateMachine.CurrentState = ControllerStates.Neutral;
            }
        },
                                        () => {
            DestroyMenuButtons(menuCurrentButtons);
            controlledSelector.Deactivate();
        }
                                        );

        controllerStateMachine.AddState(ControllerStates.OrderMenu,
                                        () => {
            controlledSelector.ActivateAndUnpause();

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Move",
                         pointerInfo.pointedPositionScreen - Vector3.right * 50f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                if (CanEditMoveOrderForSelectedEntities(controlledSelector))
                {
                    controllerStateMachine.CurrentState = ControllerStates.MoveOrderMenu;
                }
            });

            /*CreateButton(menuCurrentButtons, sampleButtonPrefab, "MoveForm",
             *  pointerInfo.pointedPositionScreen - Vector3.right * 100f,
             *  GameObject.Find("UI Screen Canvas").GetComponent<RectTransform>(),
             *  GetMyCamera()).onClick.AddListener(
             *      () => {
             *          if (CanEditMoveOrderForSelectedEntities(controlledSelector))
             *              controllerStateMachine.CurrentState = ControllerStates.MoveOrderFormationMenu;
             *      });*/

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Patrol",
                         pointerInfo.pointedPositionScreen + Vector3.right * 0f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                controllerStateMachine.CurrentState = ControllerStates.PatrolOrderMenu;
            });

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Engage at positions",
                         pointerInfo.pointedPositionScreen + Vector3.right * 50f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                controllerStateMachine.CurrentState = ControllerStates.EngageAtPositionsMenu;
            });

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Build",
                         pointerInfo.pointedPositionScreen + Vector3.right * 100f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                controllerStateMachine.CurrentState = ControllerStates.BuildOrderMenu;
            });

            //PrepareButtonsForMenu(menuCurrentButtons);
        },
                                        () => {
            EditWaypointMarkerControl();

            if (!ShapeSelectionControl(controlledSelector) &&
                Input.GetMouseButtonDown(1) &&
                NoUIAtScreenPositionExceptCanvas(pointerInfo.pointedPositionScreen, 2))
            {
                controllerStateMachine.CurrentState = ControllerStates.Menu;
            }
        },
                                        () => {
            DestroyMenuButtons(menuCurrentButtons);
            controlledSelector.Deactivate();
        }
                                        );

        controllerStateMachine.AddState(ControllerStates.MoveOrderMenu,
                                        () => {
            controlledSelector.ActivateAndUnpause();

            //PrepareButtonsForMenu(menuCurrentButtons);
        },
                                        () => {
            //if (CanEditMoveOrderForSelectedEntities(controlledSelector))

            if (!CurrentlyEditedMoveOrdersCreateWaypointsControl() &&
                Input.GetMouseButtonDown(1) &&
                NoUIAtScreenPositionExceptCanvas(pointerInfo.pointedPositionScreen, 2))
            {
                controllerStateMachine.CurrentState = ControllerStates.OrderConfirmationPrompt;
            }
        },
                                        null,
                                        null,
                                        new Dictionary <ControllerStates, System.Action>()
        {
            { ControllerStates.OrderMenu,
              () => {
                  FetchCurrentlyEditedMoveOrderWrappersFromSelectedEntities(controlledSelector);
              } }
        }
                                        );

        /*controllerStateMachine.AddState(ControllerStates.MoveOrderFormationMenu,
         *  () => {
         *      controlledSelector.ActivateAndUnpause();
         *
         *      //PrepareButtonsForMenu(menuCurrentButtons);
         *  },
         *  () => {
         *      //if (CanEditMoveOrderForSelectedEntities(controlledSelector))
         *
         *      if (!CurrentlyEditedMoveOrdersCreateWaypointsControl(1)
         *      && Input.GetMouseButtonDown(1)
         *      && NoUIAtScreenPositionExceptCanvas(pointerInfo.pointedPositionScreen, 2))
         *          controllerStateMachine.CurrentState = ControllerStates.OrderConfirmationPrompt;
         *  },
         *  null,
         *  null,
         *  new Dictionary<ControllerStates, System.Action>() {
         *      { ControllerStates.OrderMenu,
         *          () => {
         *              FetchCurrentlyEditedMoveOrderFormationWrappersFromSelectedEntities(controlledSelector);
         *          }
         *      }
         *  }
         * );*/

        controllerStateMachine.AddState(ControllerStates.BuildOrderMenu,
                                        () => {
            controlledSelector.ActivateAndUnpause();

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "FOB",
                         pointerInfo.pointedPositionScreen - Vector3.right * 50f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                controllerStateMachine.CurrentState = ControllerStates.OrderConfirmationPrompt;

                /*new BuildingMarker(
                 *  pointerInfo.pointedPositionWorld - Vector3.right * 10 * i / c);
                 * currentlyEditedOrderWrappers[i]
                 *  .GetWrappedAs<MoveOrder>()
                 *  .AddWaypoint(wpmrk.GetMyWrapper<WaypointMarker>());*/
            });

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Outpost",
                         pointerInfo.pointedPositionScreen + Vector3.right * 0f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                //dddddddddddddddddddddddddddddddddddddddddddddddd
            });

            //PrepareButtonsForMenu(menuCurrentButtons);
        },
                                        () => {
            //if (CanEditMoveOrderForSelectedEntities(controlledSelector))

            CurrentlyEditedBuildOrdersCreateMarkersControl();

            /*if (!CurrentlyEditedBuildOrdersCreateMarkersControl()
             * && Input.GetMouseButtonDown(1)
             * && NoUIAtScreenPositionExceptCanvas(pointerInfo.pointedPositionScreen, 2))
             *  controllerStateMachine.CurrentState = ControllerStates.OrderConfirmationPrompt*/;
        },
                                        null,
                                        null,
                                        new Dictionary <ControllerStates, System.Action>()
        {
            { ControllerStates.OrderMenu,
              () => {
                  FetchCurrentlyEditedBuildOrderWrappersFromSelectedEntities(controlledSelector);
              } }
        }
                                        );

        controllerStateMachine.AddState(ControllerStates.BuildOrderMenu2,
                                        () => {
            controlledSelector.ActivateAndUnpause();

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "FOB",
                         pointerInfo.pointedPositionScreen - Vector3.right * 50f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                controllerStateMachine.CurrentState = ControllerStates.OrderConfirmationPrompt;

                /*new BuildingMarker(
                 *  pointerInfo.pointedPositionWorld - Vector3.right * 10 * i / c);
                 * currentlyEditedOrderWrappers[i]
                 *  .GetWrappedAs<MoveOrder>()
                 *  .AddWaypoint(wpmrk.GetMyWrapper<WaypointMarker>());*/
            });

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Outpost",
                         pointerInfo.pointedPositionScreen + Vector3.right * 0f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                //dddddddddddddddddddddddddddddddddddddddddddddddd
            });

            //PrepareButtonsForMenu(menuCurrentButtons);
        },
                                        () => {
            //if (CanEditMoveOrderForSelectedEntities(controlledSelector))

            CurrentlyEditedBuildOrdersCreateMarkersControl();

            /*if (!CurrentlyEditedBuildOrdersCreateMarkersControl()
             * && Input.GetMouseButtonDown(1)
             * && NoUIAtScreenPositionExceptCanvas(pointerInfo.pointedPositionScreen, 2))
             *  controllerStateMachine.CurrentState = ControllerStates.OrderConfirmationPrompt*/;
        },
                                        null,
                                        null,
                                        new Dictionary <ControllerStates, System.Action>()
        {
            { ControllerStates.OrderMenu,
              () => {
                  FetchCurrentlyEditedBuildOrderWrappersFromSelectedEntities(controlledSelector);
              } }
        }
                                        );

        controllerStateMachine.AddState(ControllerStates.EngageAtPositionsMenu,
                                        () => {
        },
                                        () => {
            //if (CanEditMoveOrderForSelectedEntities(controlledSelector))

            if (!CurrentlyEditedEngageAtPositionsControl() &&
                Input.GetMouseButtonDown(1) &&
                NoUIAtScreenPositionExceptCanvas(pointerInfo.pointedPositionScreen, 2))
            {
                controllerStateMachine.CurrentState = ControllerStates.OrderConfirmationPrompt;
            }
        },
                                        null,
                                        null,
                                        new Dictionary <ControllerStates, System.Action>()
        {
            { ControllerStates.OrderMenu,
              () => {
                  FetchCurrentlyEditedEngageAtPositionsWrappersFromSelectedEntities(controlledSelector);
              } }
        }
                                        );


        ControllerStates _previousstate = default(ControllerStates);

        controllerStateMachine.AddState(ControllerStates.OrderConfirmationPrompt,
                                        () => {
            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Save/Confirm",
                         pointerInfo.pointedPositionScreen - Vector3.right * 50f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                CurrentlyEditedOrdersConfirm();
                controllerStateMachine.CurrentState = ControllerStates.Neutral;
            });

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Start Hour",
                         pointerInfo.pointedPositionScreen - Vector3.right * 25f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                // example, this is a placeholder
            });

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Other options",
                         pointerInfo.pointedPositionScreen + Vector3.right * 25f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                // example, this is a placeholder
            });

            CreateButton(menuCurrentButtons, sampleButtonPrefab, "Cancel",
                         pointerInfo.pointedPositionScreen + Vector3.right * 50f,
                         GameObject.Find("UI Screen Canvas").GetComponent <RectTransform>(),
                         GetMyCamera()).onClick.AddListener(
                () => {
                CurrentlyEditedOrdersCancel();
                controllerStateMachine.CurrentState = ControllerStates.OrderMenu;
            });

            //PrepareButtonsForMenu(menuCurrentButtons);
        },
                                        () => {
            EditWaypointMarkerControl();

            if (Input.GetMouseButtonDown(1))
            {
                //controllerStateMachine.CurrentState = ControllerStates.MoveOrderMenu;
                controllerStateMachine.CurrentState = _previousstate;
            }
        },
                                        () => {
            DestroyMenuButtons(menuCurrentButtons);
        },
                                        null,
                                        new Dictionary <ControllerStates, System.Action>()
        {
            { ControllerStates.MoveOrderMenu, () => { _previousstate = ControllerStates.MoveOrderMenu; } },
            { ControllerStates.BuildOrderMenu, () => { _previousstate = ControllerStates.BuildOrderMenu; } },
            { ControllerStates.EngageAtPositionsMenu, () => { _previousstate = ControllerStates.EngageAtPositionsMenu; } }
        }
                                        );

        controllerStateMachine.CurrentState = ControllerStates.Neutral;
    }