Targetable 的子类定义了目标可以被选择 Selectable 的子类定义了目标可以选择(一般只有Person类才能有该功能)
Inheritance: MonoBehaviour
示例#1
0
文件: Mainmenu.cs 项目: Tb95/GGJ2016
	void Start () {
        if (Input.GetJoystickNames().Length > 0 && Input.GetJoystickNames()[0].StartsWith("Controller (Xbox One"))
            joypadType = "One";
        else
            joypadType = "";

        Exitmenu.gameObject.SetActive (false);
        Startmenu.gameObject.SetActive (false);
        Optionmenu.gameObject.SetActive (false);

        float volume;
        mainMixer.GetFloat("musicVol", out volume);
        Optionmenu.transform.GetChild(0).GetComponent<Slider>().value = volume;
        mainMixer.GetFloat("sfxVol", out volume);
        Optionmenu.transform.GetChild(1).GetComponent<Slider>().value = volume;

        buttons = new List<Selectable>();
        buttons.Add(Startbuton);
        buttons.Add(Optionbuton);
        buttons.Add(Exitbutton);
        ButtonOn = buttons[0];
        Startbuton.Select();
        currentButtonIndex = 0;
        dPadPressed = false;
	}
示例#2
0
 // Use this for initialization
 void Start()
 {
     playButton = GameObject.Find ("Play").GetComponent<Selectable>();// GameObject.Find ("Play");
     playButton.interactable = false;
     //playButton. (false);
     playerNum = 1;
 }
示例#3
0
    private void NextInputField( Selectable next, InputField inputField )
    {
        // If it's an input field, also set the text caret
        inputField.OnPointerClick( new PointerEventData( system ) );

        EventSystem.current.SetSelectedGameObject( next.gameObject, new BaseEventData( system ) );
    }
示例#4
0
	private static AnimatorController GenerateSelectableAnimatorContoller(AnimationTriggers animationTriggers, Selectable target)
	{
		if (target == null)
			return null;

		// Where should we create the controller?
		var path = GetSaveControllerPath(target);
		if (string.IsNullOrEmpty(path))
			return null;

		// figure out clip names
		var normalName = string.IsNullOrEmpty(animationTriggers.normalTrigger) ? "Normal" : animationTriggers.normalTrigger;
		var highlightedName = string.IsNullOrEmpty(animationTriggers.highlightedTrigger) ? "Highlighted" : animationTriggers.highlightedTrigger;
		var pressedName = string.IsNullOrEmpty(animationTriggers.pressedTrigger) ? "Pressed" : animationTriggers.pressedTrigger;
		var disabledName = string.IsNullOrEmpty(animationTriggers.disabledTrigger) ? "Disabled" : animationTriggers.disabledTrigger;

		// Create controller and hook up transitions.
		var controller = AnimatorController.CreateAnimatorControllerAtPath(path);
		GenerateTriggerableTransition(normalName, controller);
		GenerateTriggerableTransition(highlightedName, controller);
		GenerateTriggerableTransition(pressedName, controller);
		GenerateTriggerableTransition(disabledName, controller);

		AssetDatabase.ImportAsset(path);

		return controller;
	}
示例#5
0
	// http://docs.unity3d.com/Manual/script-SelectableTransition.html
	public static void transition (Button button, Image image, Selectable.Transition _transition)
	{
		button.transition = _transition;
		if (_transition == Selectable.Transition.ColorTint) {
			button.targetGraphic = image;
		}
	}
 private static void SetDefaultColorTransitionValues(Selectable slider)
 {
   ColorBlock colors = slider.colors;
   colors.highlightedColor = new Color(0.882f, 0.882f, 0.882f);
   colors.pressedColor = new Color(0.698f, 0.698f, 0.698f);
   colors.disabledColor = new Color(0.521f, 0.521f, 0.521f);
 }
示例#7
0
    void Update()
    {
        Ray ray;
        if (SelectionMethod == SelectionType.MIDDLE_SCREEN) {
            ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2f, Screen.height/2f));
        } else { //Selection.Mouse
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        }
        RaycastHit hit;
        if (Physics.Raycast(ray, out hit, SelectionDistance)) {
            var material = hit.collider.renderer.materials.FirstOrDefault(m => m.shader == Target);
            var selectable = hit.collider.GetComponent<Selectable>();
            if (material != _current && selectable != null && selectable.enabled) {
                if (_current != null) FadeOut(_current, FadeOutTime);

                _current = material;
                _currentSelection = selectable;
                _fadingIn = true;
                FadeIn(material, FadeInTime);
            }
        } else if(_current != null) {
            _fadingIn = false;
            FadeOut(_current, FadeOutTime);
            _current = null;
            _currentSelection = null;
        }
        if (Input.GetMouseButton(0)) {
            if(_currentSelection != null) _currentSelection.Select();
        }
    }
示例#8
0
    public Selectable Select(Selectable pSelect)
    {
        if (SelectedItem != null)
            SelectedItem.Unselect();

        SelectedItem = pSelect;
        return SelectedItem;
    }
示例#9
0
    public void Unregister(Selectable piece)
    {
        if (piece is Ship)
            ships.Remove(piece as Ship);

        if(ships.Count == 0 && planets.Count == 0)
            game.RemoveFromRotation(this);
    }
示例#10
0
    public void Register(Selectable piece)
    {
        if (piece is Ship)
            ships.Add(piece as Ship);
        else if (piece is Planet)
            planets.Add(piece as Planet);

        piece.owner = this;
    }
    public void Deselect(Selectable selectable)
    {
        if (selectable == null)
            return;

        if (mSelected.Contains (selectable))
            mSelected.Remove (selectable);

        selectable.Deselect ();
    }
示例#12
0
    public void Unselect()
    {
        if (SelectedItem == null)
        {
            return;
        }

        SelectedItem.Unselect();
        SelectedItem = null;
    }
示例#13
0
        private void selectGameObject(Selectable selectable)
        {
            if (selectable != null)
            {
                InputField inputfield = selectable.GetComponent<InputField>();
                if (inputfield != null) inputfield.OnPointerClick(new PointerEventData(_system));  //if it's an input field, also set the text caret

                _system.SetSelectedGameObject(selectable.gameObject, new BaseEventData(_system));
            }
        }
 public void SpawnEnemy(int enemy, Vector3 position)
 {
     if (_players.IsPlayerOne())
     {
         Enemy newEnemy = (Enemy)Network.Instantiate(enemyPrefabs[enemy],position,Quaternion.identity,0);
         _enemyOnDeck = newEnemy;
     } else {
         Selectable newSymbol = (Selectable)Network.Instantiate(enemyPrefabs[enemy].symbol,position,enemyPrefabs[enemy].symbol.transform.rotation,0);
         _symbolOnDeck = newSymbol;
     }
 }
示例#15
0
文件: Pausemenu.cs 项目: Tb95/GGJ2016
 public void Initialize()
 {
     buttons = new List<Selectable>();
     buttons.Add(Resumebutton);
     buttons.Add(Optionbutton);
     buttons.Add(Mainbutton);
     ButtonOn = buttons[0];
     Resumebutton.Select();
     currentButtonIndex = 0;
     dPadPressed = false;
 }
示例#16
0
 /**
  * Returns a button by name
  */
 public int FindUIElement(string name, Selectable[] list)
 {
     for (int i = 0; i < list.Length; i++)
     {
         if (list[i].name == name)
         {
             return i;
         }
     }
     return -1;
 }
示例#17
0
 protected void OnMouseDown()
 {
     if (toSelect != null)
     {
         toSelect.Select();
     }
     else
     {
         toSelect = gameObject.GetComponent<Selectable>();
         toSelect.Select();
     }
 }
示例#18
0
文件: Pausemenu.cs 项目: Tb95/GGJ2016
    public void Optionpress ()
    {
        Optionmenu.gameObject.SetActive(true);
        Buttoncanvas.gameObject.SetActive(false);

        buttons.Clear();
        buttons.Add(Optionmenu.transform.GetChild(0).GetComponent<Slider>());
        buttons.Add(Optionmenu.transform.GetChild(1).GetComponent<Slider>());
        buttons.Add(Optionmenu.transform.GetChild(2).GetComponent<Button>());
        ButtonOn = buttons[0];
        currentButtonIndex = 0;
    }
示例#19
0
    public void UnselectAll(Selectable exception)
    {
        foreach (var selectable in selectables)
        {
            if (selectable == exception)
            {
                continue;
            }

            selectable.Unselect();
        }
    }
示例#20
0
文件: Mainmenu.cs 项目: Tb95/GGJ2016
    public void Exitpress()
    {
        Exitmenu.gameObject.SetActive (true);
        Startbuton.gameObject.SetActive (false);
        Optionbuton.gameObject.SetActive (false);
        Exitbutton.gameObject.SetActive (false);

        buttons.Clear();
        buttons.Add(Exitmenu.transform.GetChild(0).GetChild(1).GetComponent<Button>());
        buttons.Add(Exitmenu.transform.GetChild(0).GetChild(2).GetComponent<Button>());
        ButtonOn = buttons[0];
        currentButtonIndex = 0;
    }
示例#21
0
	/**
	 * Each frame, check for user input that would change our currently selected object
	 * Update the map and cursor appearance based on selections
	 */
	void Update () {
		// If the user clicks on the map, try to 'select' what they have clicked on
		if (Input.GetMouseButtonDown(0)) {
			// First clear the last selected object
			if (selectedObject) {
				selectedObject.GetComponent<Selectable>().deselect(GetInstanceID());
				selectedObject = null;
			}
			
			// Get the newly selected object and set it to 'selected'
			selectedObject = getSelectableAtPosition(Camera.main.ScreenToWorldPoint((Vector2) Input.mousePosition));
			
			// Make sure to 'select' the new object once we have obtained it
			if (selectedObject) {
				selectedObject.GetComponent<Selectable>().select(GetInstanceID());
			}
		}
		
		// If the user right-clicks when a Friendly Ant Unit is selected, move that unit along a path to the right clicked tile
		if (Input.GetMouseButtonDown(1) && selectedObject != null && selectedObject.isNeutralOrFriendly()) {
			Debug.Log("User right clicked to give command to unit: " + selectedObject);
		
			// Get the mouse position of where the user clicked
			Vector2 mousePos = Camera.main.ScreenToWorldPoint((Vector2) Input.mousePosition);
			
			// Get the Ant Unit scripts
			AntUnit antUnitScript = selectedObject.GetComponent<AntUnit>();
			WarriorUnit warriorUnitScript = selectedObject.GetComponent<WarriorUnit>();
			Selectable clickedOnSelectable = getSelectableAtPosition(mousePos);
			Attackable clickedOnAttackableScript = null;
			if (clickedOnSelectable && clickedOnSelectable.gameObject) {
				clickedOnAttackableScript = clickedOnSelectable.gameObject.GetComponent<Attackable>();
			}
			
			if (warriorUnitScript != null && clickedOnAttackableScript != null && !clickedOnAttackableScript.isNeutralOrFriendly()) {
				// If the thing we have selected is a WarriorUnit, and we clicked on an enemey AntUnit, 
				// set it as a target instead of a simple move
				Debug.Log("Going to attack!");
				warriorUnitScript.setTarget(clickedOnAttackableScript);
			} else if (antUnitScript != null) {
				// Set the unit on a path to their target
				Debug.Log("Giving ant move to command");
				StartCoroutine(antUnitScript.moveTo(mapManager.getTileAtPosition(mousePos), true));
			}
		}
		
		// Depending on what the user has selected and what they are currently hovering over, change the mouse cursor
		if (selectedObject != null) {
			setCursor(selectedObject);
		}
	}
示例#22
0
    public void SetSelection(Selectable thing)
    {
        if(selectionLocked)
            return;

        previousSelectedObject = selectedObject;
        ClearSelection(true);
        selectedObject = thing;
        isSelected = true;
        Highlighter.instance.SetHighlight(gameObject);
        DrawSelectionIndicators();
        BroadcastMessage("OnObjectSelect", SendMessageOptions.DontRequireReceiver);
        LockSelection(POST_SELECTION_LOCK_TIME);
    }
示例#23
0
 void adjustCurrentPosition(Selectable[] buttons)
 {
     int x = (int)currentPosition.x;
     int y = (int)currentPosition.y;
     if (x < 0)
     {
         //x += buttons.GetLength(0);
     }
     if (y < 0)
     {
         y += buttons.GetLength(0);
     }
     //x = x % buttons.GetLength(0);
     y = y % buttons.GetLength(0);
     currentPosition = new Vector2(x, y);
 }
示例#24
0
    public void ClearSelection(bool forceLock)
    {
        if(selectionLocked && !forceLock)
            return;

        if(selectedObject != null)
        {
            if(selectionLocked)
                UnlockSelection();
            selectedObject.isSelected = false;
            selectedObject.ClearSelectionIndicators();
            selectedObject.SendMessage("OnObjectDeselect", SendMessageOptions.DontRequireReceiver);
            selectedObject = null;
        }
        Highlighter.instance.SetHighlight(null);
    }
    /*public void SelectMultiple (List<Selectable> selectable)
    {
        foreach (Selectable s in mSelected)
            s.Deselect();

        mSelected = selectable;
        UseTargetedAbility (mTarget);

        mWasJustSelected = true;
    }*/
    public void Select(Selectable selectable)
    {
        mWasJustSelected = true;

        if (mSelected.Contains(selectable)) {
            this.Deselect(selectable);
            return;
        }

        foreach (Selectable s in mSelected) {
            if (s != null)
                s.Deselect();
        }

        mSelected.Clear ();

        mSelected.Add (selectable);
        mSelected[0].Select ();
    }
    void getInput()
    {
        h = Input.GetAxisRaw("Horizontal");
        v = Input.GetAxisRaw("Vertical");        

        if (Input.GetButtonDown("Jump"))
        {
            a = true;
            aLock = true;
        }        

        //ADD B BUTTON? (CLOSE BRANCHER?)

        if ((h != 0.0f || v != 0.0f || a == true) && !joypadding)
        {            
            joypadding = true;            
            but = gameObject.GetComponentInChildren<Selectable>();
            but.Select();
        }
    }
示例#27
0
    public void Select(Selectable target)
    {
        if (target)
        {
            if (_selection)
            {
                _selection.Deselected();
            }

            _selection = target;

            target.Selected();
        }
        else
        {
            if (_selection)
            {
                _selection.Deselected();
            }
        }
    }
	// Update is called once per frame
	void Update ()
    {
        if (engaged)
        {
            getInput();

            if (joypadding)
            {
                menuSelection();
            }
        }
        else
        {
            if(but != null)
            {
                but = null;
                joypadding = false;
                aLock = false;
            }            
        }        	
	}
示例#29
0
 public static bool IsSelected(this Selectable target)
 {
     return(EventSystem.current.currentSelectedGameObject != null && (target != null && EventSystem.current.currentSelectedGameObject.Equals(target.gameObject)));
 }
示例#30
0
 private float DotProduct(Selectable selectable, Vector3 direction) => Vector2.Dot(((RectTransform)selectable.gameObject.transform).position - ((RectTransform)Current.gameObject.transform).position, direction);
示例#31
0
 private static void SelectOnlyGiven(Selectable currentSelected)
 {
     DeselectSelected();
     selected.Add(currentSelected);
     currentSelected.FlipSelected();
 }
        public void Update()
        {
            Selectable next = null;

            if (LastObject == null && _system.currentSelectedGameObject != null)
            {
                //Find the last selectable object
                next = _system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown();
                while (next != null)
                {
                    LastObject = next;
                    next       = next.FindSelectableOnDown();
                }
            }

            if (Input.GetKeyDown(KeyCode.Tab) && Input.GetKey(KeyCode.LeftShift))
            {
                if (NavigationMode == NavigationMode.Manual && NavigationPath.Length > 0)
                {
                    for (var i = NavigationPath.Length - 1; i >= 0; i--)
                    {
                        if (_system.currentSelectedGameObject != NavigationPath[i].gameObject)
                        {
                            continue;
                        }

                        next = i == 0 ? NavigationPath[NavigationPath.Length - 1] : NavigationPath[i - 1];

                        break;
                    }
                }
                else
                {
                    if (_system.currentSelectedGameObject != null)
                    {
                        next = _system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnUp();
                        if (next == null && CircularNavigation)
                        {
                            next = LastObject;
                        }
                    }
                    else
                    {
                        SelectDefaultObject(out next);
                    }
                }
            }
            else if (Input.GetKeyDown(KeyCode.Tab))
            {
                if (NavigationMode == NavigationMode.Manual && NavigationPath.Length > 0)
                {
                    for (var i = 0; i < NavigationPath.Length; i++)
                    {
                        if (_system.currentSelectedGameObject != NavigationPath[i].gameObject)
                        {
                            continue;
                        }

                        next = i == (NavigationPath.Length - 1) ? NavigationPath[0] : NavigationPath[i + 1];

                        break;
                    }
                }
                else
                {
                    if (_system.currentSelectedGameObject != null)
                    {
                        next = _system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown();
                        if (next == null && CircularNavigation)
                        {
                            next = StartingObject;
                        }
                    }
                    else
                    {
                        SelectDefaultObject(out next);
                    }
                }
            }
            else if (_system.currentSelectedGameObject == null)
            {
                SelectDefaultObject(out next);
            }

            if (CircularNavigation && StartingObject == null)
            {
                StartingObject = next;
            }
            selectGameObject(next);
        }
示例#33
0
 public override void Apply(Selectable item)
 {
     Apply(item as Slider);
 }
示例#34
0
 public static IDisposable BindToInteractable(this IObservable <bool> This, Selectable selectable) =>
 This.Subscribe(x => selectable.interactable = x);
示例#35
0
 private new void Awake()
 {
     base.Awake();
     m_Selectable = GetComponent <Selectable>();
 }
示例#36
0
        /// <summary>
        /// My black vodoo script, do not use outside
        /// </summary>
        /// <param name="ScreenMgr"></param>
        /// <param name="children"></param>
        private void UpdateNavigation(ScreenManager ScreenMgr, Transform[] children)
        {
            for (int i = 0; i < children.Length; i++)
            {
                children[i].gameObject.SetActive(false);
            }

            List <Selectable> selectables = new List <Selectable>();

            for (int i = 0; i < children.Length; i++)
            {
                Transform  parent = children[i];
                BaseScreen screen = parent.GetComponent <BaseScreen>();

                if (!screen.generateNavigation)
                {
                    continue;
                }

                parent.gameObject.SetActive(true);

                selectables.Clear();
                parent.GetComponentsInChildren <Selectable>(selectables);

                Selectable[] directions = new Selectable[4];
                foreach (Selectable selectableUI in selectables)
                {
                    //Debug.Log("<b>" + parent.name + "</b>." + selectableUI.name, selectableUI);

                    Transform t = selectableUI.transform;

                    directions[0] = FindSelectable(parent, t, selectables, t.rotation * Vector3.up);
                    directions[1] = FindSelectable(parent, t, selectables, t.rotation * Vector3.right);
                    directions[2] = FindSelectable(parent, t, selectables, t.rotation * Vector3.down);
                    directions[3] = FindSelectable(parent, t, selectables, t.rotation * Vector3.left);

                    if (selectableUI is Slider)
                    {
                        Slider.Direction dir = (selectableUI as Slider).direction;
                        if (dir == Slider.Direction.TopToBottom || dir == Slider.Direction.BottomToTop)
                        {
                            directions[0] = directions[2] = null;
                        }
                        else
                        {
                            directions[1] = directions[3] = null;
                        }
                    }

                    selectableUI.navigation = new Navigation()
                    {
                        mode          = Navigation.Mode.Explicit,
                        selectOnUp    = directions[0],
                        selectOnRight = directions[1],
                        selectOnDown  = directions[2],
                        selectOnLeft  = directions[3],
                    };


                    CancelTrigger sctrigger = selectableUI.gameObject.GetComponent <CancelTrigger>();

                    if (sctrigger == null)
                    {
                        var cancelHandlerAvailable = selectableUI.GetComponent <ICancelHandler>();
                        if (cancelHandlerAvailable == null)
                        {
                            sctrigger = selectableUI.gameObject.AddComponent <CancelTrigger>();
                            sctrigger.disableCancelHandler = cancelHandlerAvailable != null;
                        }
                    }
                }
                parent.gameObject.SetActive(false);
            }
            if (ScreenMgr.defaultScreen != null)
            {
                ScreenMgr.defaultScreen.gameObject.SetActive(true);
            }
        }
示例#37
0
 public static bool CheckSelectable(Selectable button)
 {
     return(button != null && button.interactable && button.gameObject.activeInHierarchy);
 }
示例#38
0
 public override void Step(Selectable sel)
 {
     //TODO: This is probably inneficient b/c we recalculate route every frame
     sel.SetNavTarget(targetLocation);
 }
    public void BuyUpgrade(GameObject menuItem)
    {
        AudioManager.Instance.AudioSources["Tap"].Play();
        UpgradeTypes itemType = menuItem.GetComponent <GUIMenuItem> ().type;

        if (instance.ownedUpgrades.ContainsKey(itemType))
        {
            Upgrade upgrade = instance.ownedUpgrades[itemType];
            SpawnText(menuItem, upgrade);

            instance.speed.points -= upgrade.GetCost();
            instance.upgradesController.LevelUpUpgrade(itemType);
        }
        else
        {
            Upgrade upgrade = instance.allUpgrades[itemType];
            SpawnText(menuItem, upgrade);
            instance.speed.points -= upgrade.GetCost();
            instance.upgradesController.AddUpgrade(itemType);
            instance.upgradesController.LevelUpUpgrade(itemType);

            Text[] comps = menuItem.GetComponentsInChildren <Text>();
            Text   txt   = comps[2];
            txt.color = Color.magenta;
            txt       = comps[3];
            txt.color = Color.cyan;

            Selectable selectableButton = menuItem.GetComponent <Selectable>();
            ColorBlock colors           = menuItem.GetComponent <Selectable>().colors;
            colors.normalColor      = new Color(0.06f, 0.08f, 0.16f, 1.0f);
            colors.disabledColor    = new Color(0.2f, 0.2f, 0.2f, 1.0f);
            colors.highlightedColor = new Color(0.09f, 0.12f, 0.31f, 1.0f);
            selectableButton.colors = colors;

            RepairsMenuManager.Instance.AddItem(itemType);
        }

        Upgrade ownedUpgrade = instance.ownedUpgrades [itemType];

        Text[] texts = menuItem.GetComponentsInChildren <Text>();
        Text   txtx  = texts[1];
        double value = ownedUpgrade.GetCurrentLevelValue();
        string unit  = "";

        UnitsConverter.Convert(ref value, ref unit);
        txtx.text = value.ToString("f" + instance.speedDecimals) + unit + " m/s";
        txtx      = texts[2];
        double cost = ownedUpgrade.GetCost();

        unit = "";
        UnitsConverter.Convert(ref cost, ref unit);
        txtx.text = "$ " + cost.ToString("f" + instance.priceDecimals) + unit;

        txtx = texts[3];
        double val = ownedUpgrade.GetNextLevelValue() - value;

        unit = "";
        UnitsConverter.Convert(ref val, ref unit);
        float bonus = ownedUpgrade.percentValueIncrease * 100.0f;

        txtx.text = "+ " + bonus + "%" + " " + val.ToString("f" + speedDecimals) + unit;

        txtx      = texts[4];
        txtx.text = "Level\n" + ownedUpgrade.level;
    }
示例#40
0
        private static Animations.AnimatorController GenerateSelectableAnimatorContoller(AnimationTriggers animationTriggers, Selectable target)
        {
            if (target == null)
            {
                return(null);
            }

            // Where should we create the controller?
            var path = GetSaveControllerPath(target);

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            // figure out clip names
            var normalName      = string.IsNullOrEmpty(animationTriggers.normalTrigger) ? "Normal" : animationTriggers.normalTrigger;
            var highlightedName = string.IsNullOrEmpty(animationTriggers.highlightedTrigger) ? "Highlighted" : animationTriggers.highlightedTrigger;
            var pressedName     = string.IsNullOrEmpty(animationTriggers.pressedTrigger) ? "Pressed" : animationTriggers.pressedTrigger;
            var disabledName    = string.IsNullOrEmpty(animationTriggers.disabledTrigger) ? "Disabled" : animationTriggers.disabledTrigger;

            // Create controller and hook up transitions.
            var controller = Animations.AnimatorController.CreateAnimatorControllerAtPath(path);

            GenerateTriggerableTransition(normalName, controller);
            GenerateTriggerableTransition(highlightedName, controller);
            GenerateTriggerableTransition(pressedName, controller);
            GenerateTriggerableTransition(disabledName, controller);

            AssetDatabase.ImportAsset(path);

            return(controller);
        }
示例#41
0
 public UpdateNavigationData(Selectable @new, bool leftAsIs = true) : this()
 {
     Target   = @new;
     LeftAsIs = leftAsIs;
 }
示例#42
0
 private bool CanSelect(Selectable selectable)
 {
     return(selectable != null && selectable.IsInteractable() == true && selectable.isActiveAndEnabled == true && selectable.navigation.mode != Navigation.Mode.None);
 }
示例#43
0
        public void SelectFirstSelectable()
        {
            tempSelectables.Clear();

            //var selectables = Selectable.allSelectables;Selectable.al
#if UNITY_2019_1_OR_NEWER
        #if UNITY_2019_1_0 || UNITY_2019_1_1 || UNITY_2019_1_2 || UNITY_2019_1_3 || UNITY_2019_1_4
            var count = Selectable.AllSelectablesNoAlloc(ref tempSelectablesArray);
        #else
            var count = Selectable.AllSelectablesNoAlloc(tempSelectablesArray);
        #endif
            for (var i = 0; i < count; i++)
            {
                tempSelectables.Add(tempSelectablesArray[i]);
            }
#else
            tempSelectables.AddRange(Selectable.allSelectables);
#endif

            // Select from history?
            for (var i = SelectionHistory.Count - 1; i >= 0; i--)             // NOTE: Property
            {
                var oldSelection = selectionHistory[i];

                if (oldSelection != null)
                {
                    if (CanSelect(oldSelection) == true && tempSelectables.Contains(oldSelection) == true)
                    {
                        selectionHistory.RemoveRange(i, selectionHistory.Count - i);

                        oldSelection.Select();

                        return;
                    }
                }
                else
                {
                    selectionHistory.RemoveAt(i);
                }
            }

            var bestSelectable = default(Selectable);
            var bestPriority   = -1.0f;

            // Select from selectables?
            for (var i = 0; i < tempSelectables.Count; i++)
            {
                var selectable = tempSelectables[i];

                if (CanSelect(selectable) == true)
                {
                    var selectionPriority = selectable.GetComponent <LeanSelectionPriority>();
                    var priority          = 0.0f;

                    if (selectionPriority != null)
                    {
                        priority = selectionPriority.Priority;
                    }

                    if (priority > bestPriority)
                    {
                        bestSelectable = selectable;
                        bestPriority   = priority;
                    }
                }
            }

            if (bestSelectable != null)
            {
                bestSelectable.Select();
            }
        }
示例#44
0
 // Start is called before the first frame update
 void Start()
 {
     transform.position = parent.transform.position;
     this.parentSelect  = parent.GetComponent <Selectable>();
     this.parentMove    = parent.GetComponent <IMovable>();
 }
 public void MoveToSelectable(Selectable selectable)
 {
     EventSystem.current.SetSelectedGameObject(selectable.gameObject);
 }
示例#46
0
        private void handleInputNavigation()
        {
            if (eventSystem.currentSelectedGameObject == null)
            {
                return;
            }

            Selectable currentItem = eventSystem.currentSelectedGameObject.GetComponent <Selectable>();

            if (currentItem == null)
            {
                return;
            }

            Selectable nextItem      = null;
            Slider     currentSlider = currentItem.GetComponent <Slider>();

            if (InputManager.GetCurrentValue(verticalAxis) < 0)
            {
                if ((InputManager.IsDown(verticalAxis) || InputManager.IsHeld(verticalAxis)) && _nextDownTick <= Time.unscaledTime)
                {
                    nextItem      = currentItem.FindSelectableOnDown();
                    _nextDownTick = Time.unscaledTime + repeatDelay;
                }
            }

            if (InputManager.GetCurrentValue(verticalAxis) > 0)
            {
                if ((InputManager.IsDown(verticalAxis) || InputManager.IsHeld(verticalAxis)) && _nextDownTick <= Time.unscaledTime)
                {
                    nextItem      = currentItem.FindSelectableOnUp();
                    _nextDownTick = Time.unscaledTime + repeatDelay;
                }
            }

            if (InputManager.GetCurrentValue(horizontalAxis) < 0)
            {
                if ((InputManager.IsDown(horizontalAxis) || InputManager.IsHeld(horizontalAxis)) && _nextDownTick <= Time.unscaledTime)
                {
                    if (currentSlider != null)
                    {
                        currentSlider.value--;
                    }
                    else
                    {
                        nextItem = currentItem.FindSelectableOnLeft();
                    }

                    _nextDownTick = Time.unscaledTime + repeatDelay;
                }
            }

            if (InputManager.GetCurrentValue(horizontalAxis) > 0)
            {
                if ((InputManager.IsDown(horizontalAxis) || InputManager.IsHeld(horizontalAxis)) && _nextDownTick <= Time.unscaledTime)
                {
                    if (currentSlider != null)
                    {
                        currentSlider.value++;
                    }
                    else
                    {
                        nextItem = currentItem.FindSelectableOnRight();
                    }

                    _nextDownTick = Time.unscaledTime + repeatDelay;
                }
            }

            if (nextItem != null)
            {
                eventSystem.SetSelectedGameObject(nextItem.gameObject);
            }

            if (!string.IsNullOrEmpty(submitButton) && InputManager.IsDown(submitButton))
            {
                ExecuteEvents.ExecuteHierarchy(
                    eventSystem.currentSelectedGameObject,
                    GetBaseEventData(),
                    ExecuteEvents.submitHandler
                    );
            }
        }
示例#47
0
 public override void Apply(Selectable item)
 {
     base.Apply(item);
     Apply(item as Scrollbar);
 }
示例#48
0
    private bool buttonHoldDown = false; //state, so we can determine between a click and a button that's held down since last frame

    void Update()
    {
        //This is a "click" if we're pressed now, but weren't last frame.
        bool click = false;

        if (buttonHoldDown == false && Haptic.Buttons[0] != 0)
        {
            click = true;
        }
        buttonHoldDown = (Haptic.Buttons[0] != 0);


        //Determine the screen position using the stylus position and the camera matrix transforms.
        Vector3 screenPos = camera.WorldToScreenPoint(Haptic.stylusPositionWorld);

        // In this example, the "cursor" is just a UI element.
        // Moving the system mouse cursor is more dificult, and not really recomended.
        if (cursor != null)
        {
            cursor.rectTransform.position = screenPos;
        }



        PointerEventData     pointerData = new PointerEventData(EventSystem.current);
        List <RaycastResult> results     = new List <RaycastResult>();

        // Perform a raycast to get a list of all elements under the cursor.
        pointerData.position = screenPos;
        EventSystem.current.RaycastAll(pointerData, results);

        // Now that we've found the things. Let's select them ...
        bool selectedAtLeastOneThing = false;

        foreach (RaycastResult R in results)
        {
            GameObject go = R.gameObject;
            Selectable S  = go.GetComponent <Selectable>();
            if (S != null)
            {
                S.Select();
                selectedAtLeastOneThing = true;
            }

            // If we've found a button, we can click on it.
            Button B = go.GetComponent <Button>();
            if (B != null)
            {
                if (click)
                {
                    B.onClick.Invoke();
                    B.Invoke("OnPointerDown", 0.0f);
                }
                if (buttonHoldDown == false)
                {
                    B.Invoke("OnPointerUp", 0.0f);
                }
            }
        }

        //If we're not hovering over anything, deselect everything.
        // NOTE : This is pretty crude, and will interfere with anyone trying to operate the UI via keyboard.
        if (selectedAtLeastOneThing == false)
        {
            EventSystem.current.SetSelectedGameObject(null);
        }
    }
示例#49
0
 public virtual IEnumerator BombCommanderDefocus(Bomb bomb, Selectable selectable, bool frontFace)
 {
     yield return(true);
 }
示例#50
0
 public void SelectObject(Selectable selected)
 {
     Game.SelectedRobot.Value = selected?.GetComponent <RobotController>()?.RobotModel;
 }
        public void setup(ManeuverNode node, ManeuverGizmo gizmo, int i, bool replace, bool lines, bool stickyFlight)
        {
            if (node == null)
            {
                return;
            }

            _node         = node;
            _gizmo        = gizmo;
            _index        = i;
            _showLines    = lines;
            _stickyFlight = stickyFlight;

            if (replace)
            {
                _progradeIncrement = _persProgradeIncrement;
                _normalIncrement   = _persNormalIncrement;
                _radialIncrement   = _persRadialIncrement;
            }

            if (_inputButton == null)
            {
                _inputButton = Instantiate <Button>(gizmo.minusOrbitbtn);
            }

            _inputButton.transform.SetParent(gizmo.minusOrbitbtn.transform.parent);

            _buttonRect = _inputButton.GetComponent <RectTransform>();

            RectTransform oldRect = gizmo.minusOrbitbtn.GetComponent <RectTransform>();

            _buttonRect.anchoredPosition3D = oldRect.anchoredPosition3D;
            _buttonRect.position           = oldRect.position;
            _buttonRect.localScale         = oldRect.localScale;
            _buttonRect.rotation           = oldRect.rotation;
            _buttonRect.localRotation      = oldRect.localRotation;

            _inputButton.navigation = new Navigation()
            {
                mode = Navigation.Mode.None
            };

            _inputButton.onClick.RemoveAllListeners();
            _inputButton.onClick.AddListener(new UnityAction(ToggleUI));
            _inputButton.interactable = true;

            EventTrigger events = _inputButton.gameObject.AddComponent <EventTrigger>();

            events.triggers = new System.Collections.Generic.List <EventTrigger.Entry>();

            events.triggers.Add(new EventTrigger.Entry()
            {
                eventID  = EventTriggerType.PointerEnter,
                callback = MouseEnter
            });

            events.triggers.Add(new EventTrigger.Entry()
            {
                eventID  = EventTriggerType.PointerExit,
                callback = MouseExit
            });

            MouseEnter.AddListener(new UnityAction <UnityEngine.EventSystems.BaseEventData>(TriggerOnMouseEnter));
            MouseExit.AddListener(new UnityAction <UnityEngine.EventSystems.BaseEventData>(TriggerOnMouseExit));

            Selectable inputSelect = _inputButton.GetComponent <Selectable>();

            inputSelect.image.sprite = ManeuverLoader.InputButtonNormal;

            SpriteState state = inputSelect.spriteState;

            state.highlightedSprite = ManeuverLoader.InputButtonHighlight;
            state.pressedSprite     = ManeuverLoader.InputButtonActive;
            state.disabledSprite    = ManeuverLoader.InputButtonActive;
            inputSelect.spriteState = state;

            gizmo.minusOrbitbtn.onClick.RemoveAllListeners();
            oldRect.localScale = new Vector3(0.000001f, 0.000001f, 0.000001f);

            if (_pointer != null)
            {
                _pointer.worldTransform = _buttonRect;
            }
        }
 public Selectable GetSymbolOnDeck()
 {
     Selectable symbol = _symbolOnDeck;
     _symbolOnDeck = null;
     return symbol;
 }
示例#53
0
	// This needs to be used in place of start at the beginning of a new scene
	// since this gameObject doesn't get destroyed in between scenes.
	void OnLevelWasLoaded(int level)
	{
        if (instance && instance != this)
            return;
		_curArea = Manager_Game.instance.currentArea;
		imageTransition.gameObject.SetActive(true);
		Color imColor = imageTransition.color; imColor.a = 1;
		imageTransition.color = imColor;
		if (Manager_Game.usingMobile)
            eveSystem = GameObject.Find("EventSystem_Mobile");
        else
        {
            if (Manager_Game.instance.IsInMenu)
                eveSystem = GameObject.Find("EventSystem");
            else
                eveSystem = GameObject.Find("EventSystem_NotMenu");
        }
		playInputMenu = new List<GameObject>();
        if(!eveSystem)
        {
            int index = Manager_Game.usingMobile ? 2 : Manager_Game.instance.IsInMenu ? 0 : 1;
            eveSystem = Instantiate(allEventSystems[index], Vector3.zero, Quaternion.identity) as GameObject;
        }
		if (eveSystem)
		{
			if(!Manager_Game.instance.IsInMenu && !Manager_Game.usingMobile)
				foreach (Transform child in eveSystem.transform)
					playInputMenu.Add(child.gameObject);
		}
		else
			Debug.LogWarning("NO EVENT SYSTEM FOUND!");
		if (!Manager_Game.instance.IsInMenu)
		{
			_quitPauseOption = defaultPauseOption.transform.parent.GetChild(2).GetComponent<Selectable>();
            if (_quitPauseOption)
            {
                if (Application.isWebPlayer)
                    _quitPauseOption.interactable = false; // Can't quit during the web player scene.
            }
            else
                Debug.LogWarning("NO QUIT PAUSE OPTION FOUND!");
		}
		else
		{
			if (_curArea == CurrentArea.Main_Menu)
			{
				if (allMenus.Contains(null))
				{
					allMenus = new List<Menu>();
					GameObject canvasMenu = GameObject.Find("Canvas_Menu");
					if (canvasMenu)
					{
						foreach (Transform child in canvasMenu.transform)
							allMenus.Add(child.GetComponent<Menu>());
					}
					else
						Debug.LogWarning("CANVAS MENU NOT FOUND ON MAIN MENU!");
				}
			}
		}
		DisplayUI (false);

        if (Manager_Game.instance.IsInMenu)
        {
            Transform webPlayerHelpMenu = transform.Find("Panel_HelpInfo_Menu");
            if (webPlayerHelpMenu)
                webPlayerHelpMenu.gameObject.SetActive(true);
            else
                Debug.LogWarning("NO HELP INFO FOUND ON MENU!");
            if (_webPlayerParent)
                _webPlayerParent.SetActive(false); // Do not need web player help info when not on a menu screen.
        }
        else
        {
            Transform webPlayerHelpMenu = transform.Find("Panel_HelpInfo_Menu");
            if (webPlayerHelpMenu)
                webPlayerHelpMenu.gameObject.SetActive(false); // Disable the menu's controls.
            if (_curArea == CurrentArea.Demo)
            {
                _webPlayerHelpInfo = new List<GameObject>();
                Transform webPlayerParent = transform.Find("WebPlayer_HelpInfo");
                _webPlayerParent = webPlayerParent.gameObject;
                if (webPlayerParent)
                {
                    foreach (Transform child in webPlayerParent)
                        _webPlayerHelpInfo.Add(child.gameObject);
                    _webPlayerHelpInfo[0].SetActive(true);
                    _webPlayerHelpInfo[1].SetActive(false); // Disable the large body of text controls information.
                }
                else
                    Debug.LogWarning("WEB PLAYER PARENT NOT FOUND IN DEMO LEVEL!");
            }
            else
            {
                if (_webPlayerParent)
                    _webPlayerParent.SetActive(false);
            }
        }
		StartCoroutine (StartTransition (TransitionTypes.Fading, true));
	}
    void BuildMenu()
    {
        GameObject autopilotitem = GameObject.Instantiate(Resources.Load("Prefabs/AutoPilot1h")) as GameObject;

        autopilotitem.transform.SetParent(transform, false);
        autopilotitem.GetComponent <GUIMenuItem> ().type = UpgradeTypes.AutoPilot1h;
        menuItems.Add(autopilotitem);

        autopilotitem = GameObject.Instantiate(Resources.Load("Prefabs/AutoPilot6h")) as GameObject;
        autopilotitem.transform.SetParent(transform, false);
        autopilotitem.GetComponent <GUIMenuItem> ().type = UpgradeTypes.AutoPilot6h;
        menuItems.Add(autopilotitem);

        autopilotitem = GameObject.Instantiate(Resources.Load("Prefabs/AutoPilot12h")) as GameObject;
        autopilotitem.transform.SetParent(transform, false);
        autopilotitem.GetComponent <GUIMenuItem> ().type = UpgradeTypes.AutoPilot12h;
        menuItems.Add(autopilotitem);

        autopilotitem = GameObject.Instantiate(Resources.Load("Prefabs/AutoPilot3d")) as GameObject;
        autopilotitem.transform.SetParent(transform, false);
        autopilotitem.GetComponent <GUIMenuItem> ().type = UpgradeTypes.AutoPilot3d;
        menuItems.Add(autopilotitem);

        autopilotitem = GameObject.Instantiate(Resources.Load("Prefabs/AutoPilot1w")) as GameObject;
        autopilotitem.transform.SetParent(transform, false);
        autopilotitem.GetComponent <GUIMenuItem> ().type = UpgradeTypes.AutoPilot1w;
        menuItems.Add(autopilotitem);

        UpdateAutoPilotItems();

        foreach (KeyValuePair <UpgradeTypes, Upgrade> upgradeItem in allUpgrades)
        {
            Upgrade upgrade = upgradeItem.Value;
            if (upgrade.type == UpgradeTypes.AutoPilot1h || upgrade.type == UpgradeTypes.AutoPilot6h || upgrade.type == UpgradeTypes.AutoPilot12h || upgradeItem.Key == UpgradeTypes.AutoPilot3d || upgradeItem.Key == UpgradeTypes.AutoPilot1w)
            {
                continue;
            }
            else
            {
                double value = upgrade.GetCurrentLevelValue();
                string vunit = "";
                UnitsConverter.Convert(ref value, ref vunit);

                string name  = upgrade.type.ToString();
                double cost  = upgrade.GetCost();
                string cunit = "";
                UnitsConverter.Convert(ref cost, ref cunit);
                int   level = upgrade.level;
                float bonus = upgrade.percentValueIncrease * 100.0f;

                GameObject item = GameObject.Instantiate(Resources.Load("Prefabs/UpgradeMenuItem")) as GameObject;
                item.GetComponent <GUIMenuItem> ().type = upgrade.type;
                Text[] comps = item.GetComponentsInChildren <Text>();
                Text   txt   = comps[0];
                txt.text = name.ToUpper();

                if (ownedUpgrades.ContainsKey(upgrade.type))
                {
                    txt = comps[1];

                    txt.text = value.ToString("f" + speedDecimals) + vunit + " m/s";
                    txt      = comps[2];

                    txt.text = "$ " + cost.ToString("f" + priceDecimals) + cunit;
                    txt      = comps[3];
                    double val = upgrade.GetNextLevelValue() - value;
                    vunit = "";
                    UnitsConverter.Convert(ref val, ref vunit);
                    txt.text = "+ " + bonus + "%" + " " + val.ToString("f" + speedDecimals) + vunit;
                    txt      = comps[4];
                    txt.text = "Level\n" + level;
                }
                else
                {
                    Selectable selectableButton = item.GetComponent <Selectable>();
                    ColorBlock colors           = item.GetComponent <Selectable>().colors;
                    colors.normalColor      = new Color(0.91f, 0.55f, 0.0f, 1.0f);
                    colors.disabledColor    = new Color(0.68f, 0.48f, 0.16f, 1.0f);
                    colors.highlightedColor = new Color(1.0f, 0.68f, 0.0f, 1.0f);
                    selectableButton.colors = colors;
                    txt = comps[1];
                    double bvalue = upgrade.baseValue;
                    vunit = "";
                    UnitsConverter.Convert(ref bvalue, ref vunit);
                    txt.text  = bvalue.ToString("f" + speedDecimals) + vunit + " m/s";
                    txt       = comps[2];
                    txt.text  = "$ " + cost.ToString("f" + priceDecimals) + cunit;
                    txt.color = Color.black;
                    txt       = comps[3];
                    double val = upgrade.GetNextLevelValue() - bvalue;
                    vunit = "";
                    UnitsConverter.Convert(ref val, ref vunit);
                    txt.text  = "+ " + bonus + "%" + " " + val.ToString("f" + speedDecimals) + vunit;
                    txt.color = Color.black;
                    txt       = comps[4];
                    txt.text  = "NEW";
                }
                item.transform.SetParent(transform, false);
                menuItems.Add(item);
            }
            //parent = menuItems[i].transform;
        }
        //menuItems [3].transform.SetSiblingIndex (0);
    }
示例#55
0
 public static IDisposable SubscribeToInteractable(this IObservable <bool> source, Selectable selectable)
 {
     return(source.SubscribeWithState(selectable, (x, s) => s.interactable = x));
 }
示例#56
0
 public static void UpdateNavigationSettings(this Selectable target, Selectable up = null, Selectable down = null,
                                             Selectable left = null, Selectable right = null)
 {
     target.UpdateNavigationSettings(
         new UpdateNavigationData(up),
         new UpdateNavigationData(down),
         new UpdateNavigationData(left),
         new UpdateNavigationData(right));
 }
示例#57
0
    void Update()
    {
        // Flight Mode
        if (moveMode == 1)
        {
            if (moveAction.GetState(handType))
            {
                cameraRigTransform.position += (transform.forward / 10);
            }
            // Teleport Mode
        }
        else if (moveMode == 2)
        {
            if (moveAction.GetStateDown(handType))
            {
                cameraRigTransform.position += (transform.forward * 5);
            }
        }

        if (teleportAction.GetState(handType))
        {
            RaycastHit hit;

            if (Physics.Raycast(controllerPose.transform.position, transform.forward, out hit, 100, selectMask))
            {
                hitPoint = hit.point;
                ShowLaser(hit);

                target = hit.transform.GetComponent <Selectable>();

                reticle.SetActive(false);
                shouldTeleport = false;
                shouldSelect   = true;
            }
            else if ((moveMode == 0) && (Physics.Raycast(controllerPose.transform.position, transform.forward, out hit, 100, teleportMask)))
            {
                hitPoint = hit.point;
                ShowLaser(hit);

                reticle.SetActive(true);
                teleportReticleTransform.position = hitPoint + teleportReticleOffset;
                shouldTeleport = true;
                shouldSelect   = false;
            }
            else
            {
                shouldTeleport = false;
                shouldSelect   = false;
                laser.SetActive(false);
                reticle.SetActive(false);
            }
        }
        else
        {
            laser.SetActive(false);
            reticle.SetActive(false);
        }

        if (teleportAction.GetStateUp(handType) && shouldTeleport)
        {
            Teleport();
        }


        if (teleportAction.GetStateUp(handType) && shouldSelect)
        {
            Select();
        }
    }
示例#58
0
 public void field_selected(Selectable field, Vector2 mouse_position)
 {
     StartCoroutine(__field_selected(field, mouse_position));
 }
示例#59
0
        private static void DrawNavigationArrow(Vector2 direction, Selectable fromObj, Selectable toObj)
        {
            if (fromObj == null || toObj == null)
            {
                return;
            }
            Transform fromTransform = fromObj.transform;
            Transform toTransform   = toObj.transform;

            Vector2 sideDir   = new Vector2(direction.y, -direction.x);
            Vector3 fromPoint = fromTransform.TransformPoint(GetPointOnRectEdge(fromTransform as RectTransform, direction));
            Vector3 toPoint   = toTransform.TransformPoint(GetPointOnRectEdge(toTransform as RectTransform, -direction));
            float   fromSize  = HandleUtility.GetHandleSize(fromPoint) * 0.05f;
            float   toSize    = HandleUtility.GetHandleSize(toPoint) * 0.05f;

            fromPoint += fromTransform.TransformDirection(sideDir) * fromSize;
            toPoint   += toTransform.TransformDirection(sideDir) * toSize;
            float   length      = Vector3.Distance(fromPoint, toPoint);
            Vector3 fromTangent = fromTransform.rotation * direction * length * 0.3f;
            Vector3 toTangent   = toTransform.rotation * -direction * length * 0.3f;

            Handles.DrawBezier(fromPoint, toPoint, fromPoint + fromTangent, toPoint + toTangent, Handles.color, null, kArrowThickness);
            Handles.DrawAAPolyLine(kArrowThickness, toPoint, toPoint + toTransform.rotation * (-direction - sideDir) * toSize * kArrowHeadSize);
            Handles.DrawAAPolyLine(kArrowThickness, toPoint, toPoint + toTransform.rotation * (-direction + sideDir) * toSize * kArrowHeadSize);
        }
示例#60
0
        private void Awake()
        {
            m_component = GetComponent <Selectable>();

            ParseValues();
        }