예제 #1
0
    private bool CanAddSegment(ControlWheelSegment seg)
    {
        foreach (ControlWheelSegment cwseg in cwActions)
        {
            if (cwseg.Name.Equals(seg.Name))
            {
                Debug.LogWarning("Control Wheel Warning: Attempting to add Control Wheel Segment with a name to a Control Wheel that already contains a segemnt with the same name. Skipping...");
                return(false);
            }
        }

        return(true);
    }
예제 #2
0
    /// This region is for methods used to manipulate the ControlWheel's segments, called by the user.

    /**
     * AddControlWheelAction
     * Adds a new ControlWheelSegment to the ControlWheel
     */
    public void AddControlWheelAction(ControlWheelSegment cwa)
    {
        //Lazy init
        if (cwActions == null)
        {
            cwActions = new List <ControlWheelSegment>();
        }

        cwActions.Add(cwa);

        //Recreates the control wheel
        CreateControlWheel();
    }
예제 #3
0
    void Awake()
    {
        this.controlWheel = GetComponent <ControlWheel> ();
        //Remember to call Init!!! This is to ensure the scripts execute in the correct order
        this.controlWheel.Init();

        ControlWheelSegment printToConsoleSegment = new ControlWheelSegment(

            name: "Print To Console",

            action:
            //If this notation is strange to you, check out this link: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions
            () => {
            Debug.Log("Hello, world!");
        },

            //Loads the Sprite from the Resources folder
            icon: Resources.Load <Sprite>("DemoConsoleLogger/1"),

            preferredPosition: ControlWheelSegment.PreferredPosition.Bottom
            );

        ControlWheelSegment incrementor = new ControlWheelSegment(

            name: "Print To Console",

            //You don't have to pass arrow functions, you can also pass references to functions
            action: this.Increment,

            //Loads the Sprite from the Resources folder
            icon: Resources.Load <Sprite>("DemoConsoleLogger/2"),

            preferredPosition: ControlWheelSegment.PreferredPosition.Top
            );

        this.controlWheel.AddControlWheelActions(new ControlWheelSegment[] {
            printToConsoleSegment,
            incrementor
        });


        this.controlWheel.DisplayControlWheel();
    }
예제 #4
0
    private void AddNewWaveButton()
    {
        ControlWheelSegment startWave = new ControlWheelSegment(
            name: "Start Wave",
            action: () => {
            WaveManager.Instance.RunNextWave();
        },
            icon: Resources.Load <Sprite> ("Icons/Drone Icon"),
            preferredPosition: ControlWheelSegment.PreferredPosition.Down
            );


        //Currently equipped
        foreach (GameObject go in GrippedTool.CurrentlyHeldTools)
        {
            go.GetComponentInChildren <ControlWheel>().AddControlWheelAction(startWave);
        }

        defaultActions.Add(startWave);
    }
예제 #5
0
    /**
     * Used to add new actions to the wheel. Should not add more than 6 but no formal limit
     *
     */
    public void AddControlWheelAction(ControlWheelSegment cwa)
    {
        if (cwActions == null)
        {
            cwActions = new List <ControlWheelSegment> ();

            foreach (ControlWheelSegment cw in WaveManager.Instance.DefaultActions)
            {
                if (CanAddSegment(cw))
                {
                    cwActions.Add(cw);
                }
            }
        }

        if (CanAddSegment(cwa))
        {
            cwActions.Add(cwa);
        }

        CreateControlWheel();
    }
예제 #6
0
    public void SwitchGrippedObject(GrippedToolIndex index)
    {
        if (this.prevHeld != null)
        {
            currentlyHeldTools.Remove(this.prevHeld);

            this.hand.DetachObject(this.prevHeld);

            // Call this to undo HoverLock
            this.hand.HoverUnlock(this.prevHeld.GetComponent <Interactable>());

            this.prevHeld.GetComponent <HeldObject> ().OnDestroy();

            Destroy(this.prevHeld);

            if ((int)index >= (int)GrippedToolIndex.Pistol)
            {
                this.prevGunHeld = index;
            }
        }

        //audio
        switchSource.Play();

        GameObject playerHeld = Instantiate(this.playerHeldPrefabs[(int)index].gameObject);

        this.hand.HoverLock(playerHeld.GetComponent <Interactable>());

        // Attach this object to the hand
        this.hand.AttachObject(playerHeld, this.attachmentFlags);

        currentlyHeldTools.Add(playerHeld);
        //Set Up Control Wheel Actions

        if (index == GrippedToolIndex.BuildTool)
        {
            playerHeld.GetComponent <ControlWheel> ().AddControlWheelAction(
                new ControlWheelSegment(
                    name: "Switch",
                    action: () => {
                SwitchGrippedObject(prevGunHeld);
            },
                    icon: Resources.Load <Sprite>("Icons/swapIcon")
                    ));
        }
        else
        {
            ControlWheelSegment buildTool = new ControlWheelSegment(
                name: "Switch",
                action: () => {
                SwitchGrippedObject(GrippedToolIndex.BuildTool);
            },
                icon: Resources.Load <Sprite>("Icons/swapIcon")
                );

            ControlWheelSegment left = new ControlWheelSegment(
                name: "Change Gun Left",
                action: () =>
            {
                int newIndex = ((int)index + this.numGuns - 2) % this.numGuns + 1;

                SwitchGrippedObject((GrippedToolIndex)newIndex);
            },
                icon: Resources.Load <Sprite> ("Icons/left-arrow"),
                preferredPosition: ControlWheelSegment.PreferredPosition.Left
                );

            ControlWheelSegment right = new ControlWheelSegment(
                name: "Change Gun Right",
                action: () =>
            {
                int newIndex = ((int)index) % this.numGuns + 1;

                SwitchGrippedObject((GrippedToolIndex)newIndex);
            },
                icon: Resources.Load <Sprite> ("Icons/right-arrow"),
                preferredPosition: ControlWheelSegment.PreferredPosition.Right
                );

            playerHeld.GetComponent <ControlWheel> ().AddControlWheelActions(new ControlWheelSegment[] {
                left,
                buildTool,
                right,
            });
        }


        this.prevHeld = playerHeld;
    }
예제 #7
0
    private void CreateControlWheel()
    {
        foreach (GameObject seg in displaySegments)
        {
            Destroy(seg);
        }

        //Preferred Ordering
        ControlWheelSegment[] orderedSegs  = new ControlWheelSegment[cwActions.Count];
        List <int>            unsetOrdered = new List <int> ();
        List <int>            setUnordered = new List <int> ();

        //Reorder based on preference
        for (int i = 0; i < cwActions.Count; i++)
        {
            for (int j = 0; j < cwActions.Count; j++)
            {
                if (cwActions[j].PreferredIndex(cwActions.Count) == i)
                {
                    if (orderedSegs [i] == null)
                    {
                        orderedSegs [i] = cwActions [j];
                        setUnordered.Add(j);
                    }
                    else
                    {
                        Debug.LogWarning("Control Wheel Warning: Preferred Position " + i + " is already set for " + name);
                    }
                }
            }

            if (orderedSegs [i] == null)
            {
                unsetOrdered.Add(i);
            }
        }

        List <int> unsetUnordered = new List <int> ();

        for (int i = 0; i < cwActions.Count; i++)
        {
            if (setUnordered.Contains(i) == false)
            {
                unsetUnordered.Add(i);
            }
        }

        for (int i = 0; i < unsetUnordered.Count; i++)
        {
            orderedSegs [unsetOrdered [i]] = cwActions [unsetUnordered [i]];
        }

        cwActions = orderedSegs.ToList();

        displaySegments = new List <GameObject> ();
        dividingVectors = new List <Vector2> ();

        int steps = (int)(totalSteps / cwActions.Count);

        for (int i = 0; i < cwActions.Count; i++)
        {
            float angle = 2 * Mathf.PI * i / cwActions.Count;
            //shift angle to top of circle (ie by 90 degrees)
            angle += Mathf.PI / 2;

            //Shift by half of the size of one area
            angle -= Mathf.PI * 2 / (cwActions.Count * 2);

            displaySegments.Add(CreateSegmentObject(angle, 2 * Mathf.PI / cwActions.Count, steps));
            AddIconToSegment(displaySegments[i], cwActions[i].Icon, angle, 2 * Mathf.PI / cwActions.Count);

            dividingVectors.Add(new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)));
        }
    }
예제 #8
0
    protected override void Awake()
    {
        base.Awake();

        barrel = transform.GetChild(0).Find("EndOfBarrel");

        //btStatsCanvas = GetComponentInChildren<BuiltToolStatsCanvas> (true);
        btPreview     = GetComponent <BuildToolPreview> ();
        brProgressBar = GetComponent <BuildToolProgressBar> ();

        ResourceManager.Instance.btrd = GetComponentInChildren <BuildToolResourceDisplay> (true);

        heldUpdateables = new List <IHeldUpdateable> ();

        heldUpdateables.Add(btPreview);
        //heldUpdateables.Add (btStatsCanvas);

        currentID = startBuildable;

        aSource = GetComponent <AudioSource> ();

        //Control Wheel Actions
        ControlWheelSegment left = new ControlWheelSegment(
            name: "Change Buildable Left",
            action: () =>
        {
            //Mod doesn't work with negative numbers
            int newID = currentID - 1;
            if (newID < -1)
            {
                this.CurrentID = buildables.Length - 1;
            }
            else
            {
                this.CurrentID = newID;
            }

            updateUI = true;

            aSource.clip      = changeBuildClip;
            this.aSource.time = 0f;
            aSource.Play();
        },
            icon: Resources.Load <Sprite> ("Icons/left-arrow"),
            preferredPosition: ControlWheelSegment.PreferredPosition.Left);

        ControlWheelSegment right = new ControlWheelSegment(
            name: "Change Buildable Right",
            action: () =>
        {
            //Mod doesn't work with negative numbers
            int newID = currentID + 1;
            if (newID >= buildables.Length)
            {
                this.CurrentID = -1;
            }
            else
            {
                this.CurrentID = newID;
            }

            updateUI = true;

            this.aSource.clip = changeBuildClip;
            this.aSource.time = 0f;
            this.aSource.Play();
        },
            icon: Resources.Load <Sprite> ("Icons/right-arrow"),
            preferredPosition: ControlWheelSegment.PreferredPosition.Right);

        controlWheel.AddControlWheelActions(new ControlWheelSegment[] {
            left,
            right
        });
    }