Esempio n. 1
0
        public bool TaskHandler(StoryTask task)
        {
            bool done = false;

            switch (task.Instruction)
            {
            case "startevolution":

                ZeeSterEvolutie = new ZeeSterEvolutie();
                pop             = ZeeSterEvolutie.GetPop();

                done = true;
                break;

            case "evolve":


                int[] Score = new int[AgentCount];

                for (int a = 0; a < AgentCount; a++)
                {
                    GameObject go       = pop[a].GameObject;
                    float      distance = 0;

                    if (go != null)
                    {
                        distance = go.transform.position.magnitude;
                    }


                    Score[a] = (int)(distance);

                    pop = ZeeSterEvolutie.Evolution(Score);
                }



                done = true;
                break;

            case "spawn":

                //int AgentCount = 10;


                for (int a = 0; a < AgentCount; a++)
                {
                    // Shape input

                    Zeester ster = pop[a];



                    int   NumberOfLegs = ster.NumberOfLegs;
                    int   LegLength    = ster.LegLength;
                    float Hue          = 1f / 7f * ster.Hue;
                    float Sat          = 1f / 7f * ster.Sat;
                    float Val          = 1f / 7f * ster.Val;

                    // Behaviour input
                    float Freq  = (1f / 7f * ster.Freq) * 4f;
                    float Amp   = 5f + 5f * ster.Amp;  //0-7
                    float Phase = 1f / 7f * ster.Phase;


                    /*
                     * int NumberOfLegs = Random.Range(1, 8);
                     * int LegLength = Random.Range(1, 8);
                     * float Hue = Random.Range(0f, 1f);
                     * float Sat = Random.Range(0f, 1f);
                     * float Val = Random.Range(0f, 1f);
                     *
                     * // Behaviour input
                     * float Freq = Random.Range(0f, 4f);
                     * float Amp = Random.Range(5f, 45f);
                     * float Phase = Random.Range(0f, 1f);
                     */
                    // Spawn

                    //    Log("h: " + Hue);

                    GameObject body = Instantiate(BodyPrefab);
                    ster.GameObject = body;

                    body.transform.SetParent(Root.transform, false);
                    body.transform.localPosition = new Vector3(0, 0, Random.Range(0f, 4f));
                    Agent agt = body.GetComponent <Agent>();
                    agt.Legs = new GameObject[NumberOfLegs];

                    Material newMaterial = new Material(Shader.Find("Standard"));
                    newMaterial.color = Color.HSVToRGB(Hue, Sat, Val);

                    //newMaterial.color = Color.red;
                    agt.mat = newMaterial;

                    body.GetComponentInChildren <Renderer>().material = newMaterial;

                    for (int l = 0; l < NumberOfLegs; l++)
                    {
                        GameObject Leg = Instantiate(LegPrefab);
                        Leg.transform.SetParent(body.transform, false);
                        Leg.transform.localScale    = new Vector3(1, 1, LegLength);
                        Leg.transform.localRotation = Quaternion.Euler(10f, 360f / NumberOfLegs * l, 0);
                        Leg.transform.GetChild(0).transform.localPosition = new Vector3(0, 0, 0.5f);
                        agt.Legs[l] = Leg;

                        Leg.GetComponentInChildren <Renderer>().material = newMaterial;
                    }

                    agt.Freq  = Freq;
                    agt.Amp   = Amp;
                    agt.Phase = Phase;
                }



                done = true;

                break;


            case "kill":


                foreach (Transform child in Root.transform)
                {
                    Destroy(child.gameObject);
                }


                done = true;
                break;

            case "makeinterface":

                // Create a controller
                Controller = new Controller();

                // Create a layout (can hold multiple planes and interfaces)
                MainLayout = new Layout();

                // Create a plane
                //Plane UpperPlane3d = new Plane(GameObject.Find("UpperPlane"));
                //Plane LowerPlane3d = new Plane(GameObject.Find("LowerPlane"));

                // Create an interface
                UpperInterface = new InterFace(UserCanvas.gameObject, "upper");
                //LowerInterface = new InterFace(UserCanvas.gameObject, "lower");

                // Create a mapping and add it to the interface
                MainMapping = new Mapping();
                MainMapping.ux_single_none += Methods.OrbitCamera;
                MainMapping.ux_double_none += Methods.LateralCamera;
                MainMapping.ux_double_none += Methods.LongitudinalCamera;
                MainMapping.ux_single_2d   += Methods.Drag2D;
                MainMapping.ux_tap_2d      += Methods.tapButton2D;

                // Create an orbit cam with a pitch constraint.
                Constraint orbitConstraint = new Constraint()
                {
                    pitchClamp    = true,
                    pitchClampMin = 15f,
                    pitchClampMax = 85f
                };

                UiCam3D uppercam = new UiCam3D(GameObject.Find("MainCamera"));
                uppercam.AddContraint(orbitConstraint);

                //UiCam3D lowercam = new UiCam3D(GameObject.Find("CameraLower"));
                //lowercam.AddContraint(orbitConstraint);

                // Create an exit button and add it to the interface
                //button = new Button("Exit");
                //button.AddConstraint(Constraint.LockInPlace(button));
                //button.AddCallback("startmenu");
                //UpperInterface.addButton(button);

                // Add together.

                UpperInterface.AddUiCam3D(uppercam);
                //LowerInterface.AddUiCam3D(lowercam);

                UpperInterface.AddMapping(MainMapping);
                //LowerInterface.AddMapping(MainMapping);

                //UpperPlane3d.AddInterface(UpperInterface);
                //LowerPlane3d.AddInterface(LowerInterface);

                // Add to layout
                MainLayout.AddInterface(UpperInterface);
                //MainLayout.AddPlane(UpperPlane3d);
                //MainLayout.AddPlane(LowerPlane3d);

                done = true;

                break;

            case "interface":

                // Update the interface(s) and get result.

                UserCallBack result = Controller.updateUi(MainLayout);

                if (result.trigger)
                {
                    Log("User tapped " + result.sender + ", starting storyline " + result.label);
                    Director.Instance.NewStoryLine(result.label);
                }

                break;



            case "task1":
            case "task2":
            case "task3":
            case "repeatingtask":

                if (task.GetFloatValue("wait", out wait))
                {
                    done |= Time.time > wait;
                }
                else
                {
                    task.SetFloatValue("wait", Time.time + 3f);
                    Log("Executing task " + task.Instruction);
                }
                break;

            case "wait5":

                if (task.GetFloatValue("wait", out wait))
                {
                    done |= Time.time > wait;
                }
                else
                {
                    task.SetFloatValue("wait", Time.time + 5f);
                }
                break;


            case "wait10":

                if (task.GetFloatValue("wait", out wait))
                {
                    done |= Time.time > wait;
                }
                else
                {
                    task.SetFloatValue("wait", Time.time + 10f);
                }
                break;

            default:
                done = true;

                break;
            }

            return(done);
        }
Esempio n. 2
0
        public bool TaskHandler(StoryTask task)
        {
            bool done = false;

            switch (task.Instruction)
            {
            case "makeinterface2d":

                // Create a controller
                Controller = new Controller();

                // Create a layout (can hold multiple planes and interfaces)
                MainLayout = new Layout();

                // Create an interface
                MainInterface = new InterFace(UserCanvas.gameObject, "demo");

                // Create a mapping and add it to the interface
                MainMapping = new Mapping();
                MainMapping.ux_single_2d += Methods.Drag2D;
                MainMapping.ux_tap_2d    += Methods.tapButton2D;
                MainInterface.AddMapping(MainMapping);

                // Create a free moving button and add it to the interface
                Button button;
                button = new Button("Freemoving");
                button.AddCallback("freemovingcallback");
                MainInterface.addButton(button);

                // Create a free moving button and add it to the interface
                button = new Button("Locked");
                button.AddCallback("lockedcallback");
                button.AddConstraint(Constraint.LockInPlace(button));
                MainInterface.addButton(button);


                // Create a constrained button and add it to the interface. Coordinates are local.

                Constraint slideConstraint = new Constraint()
                {
                    hardClamp     = true,
                    hardClampMin  = new Vector2(-250f, 350f),
                    hardClampMax  = new Vector2(250f, 350f),
                    edgeSprings   = true,
                    edgeSpringMin = new Vector2(-200f, 350f),
                    edgeSpringMax = new Vector2(200f, 350f)
                };

                button = new Button("Slide");
                button.AddConstraint(slideConstraint);
                MainInterface.addButton(button);

                // Create a button with spring positions and add it to the interface.

                Constraint springConstraint = new Constraint()
                {
                    hardClamp       = true,
                    hardClampMin    = new Vector2(-250f, 250f),
                    hardClampMax    = new Vector2(250f, 250f),
                    springs         = true,
                    springPositions = new Vector2[]
                    {
                        new Vector2(-200f, 250f),
                        new Vector2(-100f, 250f),
                        new Vector2(0f, 250f),
                        new Vector2(100f, 250f),
                        new Vector2(200f, 250f)
                    }
                };

                button = new Button("Springs");
                button.AddConstraint(springConstraint);
                MainInterface.addButton(button);

                // Create two buttons with the same drag target, so they work as a group.

                button = new Button("Option1", GameObject.Find("MenuFree"));
                MainInterface.addButton(button);
                button = new Button("Option2", GameObject.Find("MenuFree"));
                MainInterface.addButton(button);

                // Create a button with orthogonal dragging (so either horizontal or vertical) and add it to the interface.

                Constraint verticalConstraint = new Constraint()
                {
                    hardClamp    = true,
                    hardClampMin = new Vector2(0f, -200f),
                    hardClampMax = new Vector2(0f, 200f)
                };
                Constraint horizontalConstraint = new Constraint()
                {
                    hardClamp    = true,
                    hardClampMin = new Vector2(-200f, -350f),
                    hardClampMax = new Vector2(200f, -350f)
                };


                button = new Button("Ortho");
                button.AddOrthoConstraints(GameObject.Find("Layer"), horizontalConstraint, GameObject.Find("Sublayer"), verticalConstraint);
                //button.AddConstraint(circleConstraint);
                MainInterface.addButton(button);

                // Create a button with circular constraint  and add it to the interface.
                // Works from 0,0 local position

                Constraint circleConstraint = new Constraint()
                {
                    radiusClamp    = true,
                    radiusClampMin = 100f,
                    radiusClampMax = 100f
                };

                button = new Button("Circle");
                button.AddConstraint(circleConstraint);
                MainInterface.addButton(button);

                // Create a free moving button and add it to the interface
                button = new Button("Exit");
                button.AddConstraint(Constraint.LockInPlace(button));
                button.AddCallback("startmenu");
                MainInterface.addButton(button);

                // Just using single plane for demo, add the interface to it
                MainLayout.AddInterface(MainInterface);

                done = true;

                break;

            case "makeinterfaceplanes":


                // Create a controller
                Controller = new Controller();

                // Create a layout (can hold multiple planes and interfaces)
                MainLayout = new Layout();

                // Create a plane
                Plane UpperPlane = new Plane(GameObject.Find("UpperPlane"));
                Plane LowerPlane = new Plane(GameObject.Find("LowerPlane"));

                // Create an interface
                UpperInterface = new InterFace(UserCanvas.gameObject, "upper");
                LowerInterface = new InterFace(UserCanvas.gameObject, "lower");

                // Create a mapping and add it to the interface
                MainMapping = new Mapping();
                MainMapping.ux_single_2d += Methods.Drag2D;
                MainMapping.ux_tap_2d    += Methods.tapButton2D;

                // Add together.

                UpperInterface.AddMapping(MainMapping);
                UpperPlane.AddInterface(UpperInterface);
                LowerInterface.AddMapping(MainMapping);
                LowerPlane.AddInterface(LowerInterface);

                // Create buttons

                button = new Button("Button01");
                UpperInterface.addButton(button);
                button = new Button("Button02");
                LowerInterface.addButton(button);

                // Create an exit button and add it to the interface
                button = new Button("Exit");
                button.AddConstraint(Constraint.LockInPlace(button));
                button.AddCallback("startmenu");
                UpperInterface.addButton(button);

                // Add to layout.

                MainLayout.AddPlane(UpperPlane);
                MainLayout.AddPlane(LowerPlane);

                done = true;
                break;

            case "makeinterfaceplanes3d":

                // Create a controller
                Controller = new Controller();

                // Create a layout (can hold multiple planes and interfaces)
                MainLayout = new Layout();

                // Create a plane
                Plane UpperPlane3d = new Plane(GameObject.Find("UpperPlane"));
                Plane LowerPlane3d = new Plane(GameObject.Find("LowerPlane"));

                // Create an interface
                UpperInterface = new InterFace(UserCanvas.gameObject, "upper");
                LowerInterface = new InterFace(UserCanvas.gameObject, "lower");

                // Create a mapping and add it to the interface
                MainMapping = new Mapping();
                MainMapping.ux_single_none += Methods.OrbitCamera;
                MainMapping.ux_double_none += Methods.LateralCamera;
                MainMapping.ux_double_none += Methods.LongitudinalCamera;
                MainMapping.ux_single_2d   += Methods.Drag2D;
                MainMapping.ux_tap_2d      += Methods.tapButton2D;

                // Create an orbit cam with a pitch constraint.
                Constraint orbitConstraint = new Constraint()
                {
                    pitchClamp    = true,
                    pitchClampMin = 15f,
                    pitchClampMax = 85f
                };

                UiCam3D uppercam = new UiCam3D(GameObject.Find("CameraUpper"));
                uppercam.AddContraint(orbitConstraint);

                UiCam3D lowercam = new UiCam3D(GameObject.Find("CameraLower"));
                lowercam.AddContraint(orbitConstraint);

                // Create an exit button and add it to the interface
                button = new Button("Exit");
                button.AddConstraint(Constraint.LockInPlace(button));
                button.AddCallback("startmenu");
                UpperInterface.addButton(button);

                // Add together.

                UpperInterface.AddUiCam3D(uppercam);
                LowerInterface.AddUiCam3D(lowercam);

                UpperInterface.AddMapping(MainMapping);
                LowerInterface.AddMapping(MainMapping);

                UpperPlane3d.AddInterface(UpperInterface);
                LowerPlane3d.AddInterface(LowerInterface);

                // Add to layout

                MainLayout.AddPlane(UpperPlane3d);
                MainLayout.AddPlane(LowerPlane3d);

                done = true;

                break;

            case "interface":

                // Update the interface(s) and get result.

                UserCallBack result = Controller.updateUi(MainLayout);

                if (result.trigger)
                {
                    Log("User tapped " + result.sender + ", starting storyline " + result.label);
                    Director.Instance.NewStoryLine(result.label);
                }

                break;

            case "startallsamples":

                SceneManager.LoadScene("AllSamples", LoadSceneMode.Single);
                done = true;
                break;

            default:
                done = true;

                break;
            }

            return(done);
        }