예제 #1
0
    // Use this for initialization
    void Start()
    {
        UnityARSessionNativeInterface.ARSessionShouldAttemptRelocalization = true;

        // user finished the intro screens :
        PlayerPrefs.SetInt("LoadedMain_version_1.5", 1);

        UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;

        Message.text = "Look around with camera and tap on yellow plus...";
        Help(false);
        About(false);
        undoObjects = new List <GameObject>();
        PartSelector.SetActive(false);
        CursorScale.SetActive(false);
        ModalButtons.SetActive(false);

        floatingListArray = Resources.LoadAll <GameObject>("Floating");
        floatingList      = floatingListArray.ToList();

        // set selected item to first

        Destroy(SelectionMesh);
        SelectionMesh = Instantiate(floatingList[0], new Vector3(0, 0, 0), Quaternion.identity);
        SelectionMesh.transform.parent = SelectedMesh.transform;

        SetupSelectionObject(SelectionMesh, SelectionButtonScale);

        foreach (GameObject item in floatingListArray)
        {
            GameObject NewObject = Instantiate(item, new Vector3(0, 0, 0), Quaternion.identity);
            NewObject.transform.parent = Items.transform;

            SetupSelectionObject(NewObject, 3.75f);

            foreach (Animation animation in NewObject.GetComponentsInChildren(typeof(Animation)))
            {
                animation.playAutomatically = false;
            }

            MySelector.UpdateItemsList();

            MalbersAnimations.Selector.MItem NewMItem = NewObject.GetComponent <MalbersAnimations.Selector.MItem>();

            NewMItem.originalItem = item;

            // set selected item to the first one
            if (!MySelectorController.SelectedGameObject)
            {
                MySelectorController.SelectedGameObject = NewMItem.originalItem;
            }
        }
    }
예제 #2
0
 /// <summary>Purchase item</summary>
 public void Purchase(MItem item)
 {
     if (Data)
     {
         if (Data.Save.Coins - item.Value >= 0)          //If we have money to buy?
         {
             Data.Save.Coins -= item.Value;
             item.Locked      = false;           //Unlock the Item
         }
         Data.UpdateData(this);
     }
     else
     {
         item.Locked = false;
         // Controller.UpdateLockItems();
     }
 }
예제 #3
0
        //──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
        private void UpdateSelectedItem(GameObject item)
        {
            if (item == null)
            {
                return;
            }
            ItemSelected = item.GetComponent <MItem>();

            if (ItemSelected)
            {
                if (ItemSelected.originalItem == null)
                {
                    ItemSelected.originalItem = item.gameObject;
                }
                OriginalItemSelected = ItemSelected.OriginalItem;
            }
        }
예제 #4
0
        private void RemoveItemCommon(MItem toRemove)
        {
            if (toRemove == null)
            {
                return;
            }

            int toRemoveIndex = Editor.Items.FindIndex(item => item == toRemove);           //Find the index of the item to remove..

            if (Controller.FocusedItemIndex > toRemoveIndex)
            {
                Controller.FocusedItemIndex--;
            }

            Destroy(toRemove.gameObject);

            StartCoroutine(CheckItemsNextFrame());                                            //Destroy first then the next frame update all
        }
예제 #5
0
        /// <summary>
        /// Set an item tranform values on the Final State of a Transform Animation
        /// </summary>
        protected virtual void EndAnimationTransform(MItem item, TransformAnimation animTransform)
        {
            //if (item == PreviousItem) return; ERROR OF THE ESA TALLA GLitch

            if (item == null)
            {
                return;
            }

            //Set to the Last Value on the Curve POS ROT and SCALE
            if (animTransform.UsePosition)
            {
                item.transform.localPosition = item.StartPosition +
                                               transform.InverseTransformDirection(item.transform.TransformDirection(animTransform.Position * animTransform.PosCurve.Evaluate(1)));
            }


            if (animTransform.UseRotation)
            {
                if (S_Editor.UseWorld)
                {
                    item.transform.localRotation = UseWorldRotation * item.StartRotation * Quaternion.Euler(animTransform.Rotation * animTransform.RotCurve.Evaluate(1));
                }
                else
                {
                    item.transform.localRotation = item.StartRotation * Quaternion.Euler(animTransform.Rotation * animTransform.RotCurve.Evaluate(1));
                }
            }

            if (animTransform.UseScale)
            {
                item.transform.localScale = Vector3.LerpUnclamped(item.StartScale, Vector3.Scale(item.StartScale, animTransform.Scale), animTransform.ScaleCurve.Evaluate(1));
            }
            ;

            isAnimating = false;

            //if (!IsSelectTransformAnimation)                                               //Don't Store if is doing an Idle Animation //Para que no se escale pa abajo o siga subiendo foreva
            //{
            //    LastTCurrentItem.LocalPosition = item.transform.localPosition;              //Store the last local position after the animation
            //    LastTCurrentItem.LocalScale = item.transform.localScale;                //Store the last local Scale after the animation
            //}
        }
예제 #6
0
        /// <summary>
        /// Add ItemsManager to all Childs and colliders
        /// </summary>
        public virtual void AddItemScript(Transform child)
        {
            MItem mitem = child.GetComponent <MItem>();

            //Add ItemsManagerScript
            if (!mitem)
            {
                mitem = child.gameObject.AddComponent <MItem>();
            }

            child.gameObject.SetLayer(LayerMask.NameToLayer("UI"), true);  //Set the Layer to UI.

            Renderer renderer = child.GetComponentInChildren <Renderer>(); //Find the Renderer for this Item

            if (!child.GetComponent <Collider>())                          //Check First if there's no collider
            {
                if (!renderer)
                {
                    return;
                }

                if (renderer is MeshRenderer || renderer is SkinnedMeshRenderer)            //if the Item is a 3D Model
                {
                    if (!renderer.GetComponent <Collider>())
                    {
                        renderer.gameObject.AddComponent <BoxCollider>();
                    }
                }

                if (renderer is SpriteRenderer)
                {
                    if (!renderer.GetComponent <Collider2D>())
                    {
                        renderer.gameObject.AddComponent <BoxCollider2D>();
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        ///Drag/Swipe with Mouse/Touch and Action by Click/Tap
        /// </summary>
        protected virtual void SelectionAction()
        {
            CurrentEventData.position = Input.mousePosition;

            #region Hover && SoloSelection
            if (Hover && SoloSelection)
            {
                List <RaycastResult> results = new List <RaycastResult>();
                EventSystem.current.RaycastAll(CurrentEventData, results); //HERE IS THE MODIfICATION

                if (results.Count > 0)
                {
                    GameObject HitObject = results[0].gameObject;

                    if (HitObject.GetComponentInParent <SelectorManager>() != S_Manager)
                    {
                        return;                                                                 //Its not the same selector Skip All
                    }
                    MItem HitObjectItem = HitObject.GetComponentInParent <MItem>();

                    if (HitItem != HitObjectItem)
                    {
                        HitItem = HitObjectItem;

                        if (HitItem)
                        {
                            int Next = Items.FindIndex(item => item == HitItem);
                            if (IndexSelected != Next)
                            {
                                IndexSelected = Next;

                                if (PreviousItem && !PreviousItem.IsRestoring)
                                {
                                    StartCoroutine(RestoreTransformAnimation(PreviousItem)); //If is not restoring the Previous Item Restore it
                                }
                            }
                            if (MainInputDown)
                            {
                                IsSelectTransformAnimation = true;
                                OnClickOnItem.Invoke(CurrentItem.gameObject);           //Invoke OnClick Event on the Controller
                                CurrentItem.OnSelected.Invoke();                        //Invoke OnSelected Event on the Item
                            }
                        }
                    }
                }
                //return;  //Skip everything else
            }
            #endregion
            if (MainInputDown)                                          //The moment the mouse/touch start the click/touch
            {
                MouseStartPosition = Input.mousePosition;               //Store the mouse/touch start position
                DeltaSelectorT.StoreTransform(transform);               //Store the Current Selector Transform Data

                IsSwapping = false;                                     //Set swapping to false
            }
            if (SoloSelection)
            {
                DeltaMousePos = Vector2.zero;
                goto ReleaseMouse;
            }

            #region DRAG/SWIPE on MOUSE/TOUCH

            if (MainInputPress)                                                                             //if we are still touching means that we are dragging/swiping
            {
                DeltaMousePos = MouseStartPosition - Input.mousePosition;                                   //Store the amount of distance travelled sice the first click/touch

                if (DeltaMousePos.magnitude > Threshold && !IsSwapping && DragSpeed != 0 && !SoloSelection) //Find out if is a Swipe/Drag
                {
                    IsSwapping = true;                                                                      //Is a Drag/Swipe!!

                    StartCoroutine(RestoreTransformAnimation(CurrentItem));                                 //Restore the Current Item to their last pos
                }

                #region Dragin and Swapping if Animate Selection is Active

                if (AnimateSelection && IsSwapping && DragSpeed != 0)                                   //Just Drag if Animate Selection is active
                {
                    #region Drag Radial
                    if (S_Editor.SelectorType == SelectorType.Radial)                 //If is a Radial Selector-----------------------------------------------------------
                    {
                        DragDistance = dragHorizontal ? DeltaMousePos.x : DeltaMousePos.y;

                        DragDistance = DragDistance * Time.fixedDeltaTime * DragSpeed;

                        //Rotate while drag
                        switch (S_Editor.RadialAxis)
                        {
                        case RadialAxis.Up:
                            transform.localEulerAngles = DeltaSelectorT.LocalEulerAngles + new Vector3(0, DragDistance, 0);                 //Rotate  on Y axis the Selector
                            break;

                        case RadialAxis.Right:
                            transform.localEulerAngles = DeltaSelectorT.LocalEulerAngles + new Vector3(DragDistance, 0, 0);                 //Rotate on X axis the Selector This one has probems with gimbal
                            break;

                        case RadialAxis.Forward:
                            transform.localEulerAngles = DeltaSelectorT.LocalEulerAngles + new Vector3(0, 0, DragDistance);                  //Rotate  on Z axis the Selector
                            break;

                        default:
                            break;
                        }

                        if (IsSwapping)
                        {
                            CheckForWorldRotation();                //Align Items to the World if Use World is Active
                        }
                    }
                    #endregion
                    #region Drag Linear
                    else if (S_Editor.SelectorType == SelectorType.Linear)                                  //If is a Linear Selector-----------------------------------------------------------
                    {
                        float magnitude = dragHorizontal ? DeltaMousePos.x : DeltaMousePos.y;

                        DragDistance = -(DeltaSelectorT.LocalPosition - InitialTransform.LocalPosition).magnitude + (-magnitude * DragSpeed * 0.002f);

                        float maxDistance = -distance * (Items.Count - 1);
                        DragDistance = Mathf.Clamp(DragDistance, maxDistance, 0);

                        transform.localPosition = InitialTransform.LocalPosition + S_Editor.LinearVector * DragDistance;
                    }
                    #endregion
                    #region Drag Grid
                    else if (S_Editor.SelectorType == SelectorType.Grid)
                    {
                        transform.localPosition = GridVector();
                    }
                    #endregion
                }
                #endregion
            }
            #endregion

            #region Release Mouse Click/Touch

ReleaseMouse:

            if (MainInputUp)                              //if is released the Click/Touch───────────────────────────────────────────────────────────────────────────────────────
            {
                IsSwapping = false;                       //Set Swapping to false

                if (DeltaMousePos.magnitude <= Threshold) //if it was a CLICK/TAP and it was not on top a IU Element
                {
                    List <RaycastResult> results = new List <RaycastResult>();
                    EventSystem.current.RaycastAll(CurrentEventData, results);

                    if (results.Count > 0)
                    {
                        MItem HitItem = results[0].gameObject.GetComponentInParent <MItem>();

                        if (HitItem)
                        {
                            if (HitItem.GetComponentInParent <SelectorManager>() != S_Manager)
                            {
                                return;                                                                     //Its not the same Selector
                            }
                            int Next = Items.FindIndex(item => item == HitItem);

                            if (IndexSelected == Next)                                                      //If we Click/Touch the Selected item Invoke |ON CLICK|
                            {
                                IsSelectTransformAnimation = true;
                                OnClickOnItem.Invoke(current.gameObject);                   //Invoke OnClick Event on the Controller
                                current.OnSelected.Invoke();                                //Invoke OnSelected Event on the Item
                            }
                            else                                                            //If another visible item was touch change to that one;
                            {
                                if (ClickToFocus)
                                {
                                    IndexSelected = Next;                                   //Focus on the Next Item if lcick to focus is Active
                                }
                            }
                        }
                    }
                    else if (ChangeOnEmptySpace)               // if we did not hit any item the it was a click/touch on Left or Right of the Screen
                    {
                        Vector2 center = new Vector2(Screen.width / 2f, Screen.height / 2f);

                        if ((Input.mousePosition.x < center.x && dragHorizontal) || ((Input.mousePosition.y < center.y && !dragHorizontal)))
                        {
                            SelectNextItem(false);
                        }
                        else
                        {
                            SelectNextItem(true);
                        }
                    }
                }

                else if (DragSpeed != 0)                              //Else if it was a swipe and swipe is active, average to the nearest item on the camera view
                {
                    if (S_Editor.SelectorType == SelectorType.Radial) //Circular Selector---------------------------
                    {
                        int Next = Mathf.RoundToInt(DragDistance / S_Editor.Angle);

                        if (S_Editor.RadialAxis != RadialAxis.Up)
                        {
                            Next = -Next;
                        }

                        if (Next < 0)
                        {
                            Next = Items.Count + (Next % Items.Count);
                        }

                        IndexSelected += Next;                             // ????????????????????
                    }
                    else if (S_Editor.SelectorType == SelectorType.Linear) //Linear Selector---------------------------
                    {
                        IndexSelected = Mathf.RoundToInt(Mathf.Abs(DragDistance) / distance) % Items.Count;
                    }
                    else if (S_Editor.SelectorType == SelectorType.Grid)                   //Grid Selector---------------------------
                    {
                        Vector3 DragMouse = GridVector() - InitialTransform.LocalPosition; //Get the Position on the Grid

                        int   Next = 0;
                        float mag  = float.MaxValue;

                        for (int i = 0; i < Items.Count; i++)
                        {
                            float currentmag = Mathf.Abs((DragMouse + Items[i].transform.localPosition).magnitude); //Find the nearest item.

                            if (currentmag < mag)
                            {
                                Next = i;
                                mag  = currentmag;
                            }
                        }
                        IndexSelected = Next;       //Set the Focused Item to the next
                    }
                    DragDistance = 0;               //Reset Drag Distance
                }
            }
            #endregion
        }
예제 #8
0
        /// <summary>
        /// Positions all items depending of the selector type
        /// </summary>
        public void ItemsLocation(Transform item, int ID)
        {
            Vector3 posItem = Vector3.zero;
            MItem   m_item  = item.GetComponent <MItem>();

            switch (SelectorType)
            {
            case SelectorType.Radial:
            {
                switch (RadialAxis)
                {
                case RadialAxis.Up:
                    posItem = new Vector3(Mathf.Cos(Angle * ID * Mathf.PI / 180) * distance, 0, Mathf.Sin(Angle * ID * Mathf.PI / 180) * distance);
                    break;

                case RadialAxis.Right:
                    posItem = new Vector3(0, Mathf.Cos(Angle * ID * Mathf.PI / 180) * distance, Mathf.Sin(Angle * ID * Mathf.PI / 180) * distance);
                    break;

                case RadialAxis.Forward:
                    posItem = new Vector3(Mathf.Cos(Angle * ID * Mathf.PI / 180) * distance, Mathf.Sin(Angle * ID * Mathf.PI / 180) * distance, 0);
                    break;

                default:
                    break;
                }
            }
            break;

            case SelectorType.Linear:
                posItem = LinearVector * (distance * ID / 2);
                break;

            case SelectorType.Grid:
                posItem = new Vector3(ID % Grid * GridWidth, ID / Grid * GridHeight);
                break;

            case SelectorType.Custom:

                if (m_item)
                {
                    item.transform.localPosition = m_item.CustomPosition;
                    item.transform.localRotation = m_item.CustomRotation;
                    item.transform.localScale    = m_item.CustomScale;

                    goto SetStartTransform;
                }
                break;

            default:
                break;
            }

            item.transform.localPosition = posItem;

            item.localRotation = Quaternion.identity;

            if (LookRotation)
            {
                Vector3 LookRotationAxis = Vector3.up;
                if (RadialAxis == RadialAxis.Right)
                {
                    LookRotationAxis = Vector3.right;
                }
                if (RadialAxis == RadialAxis.Forward)
                {
                    LookRotationAxis = Vector3.forward;
                }

                item.transform.LookAt(transform, LookRotationAxis);
            }

            item.localRotation *= Quaternion.Euler(RotationOffSet);

SetStartTransform:

            if (m_item)
            {
                m_item.StartPosition = item.localPosition;
                m_item.StartRotation = item.localRotation;
                m_item.StartScale    = item.localScale;
            }
        }
예제 #9
0
        /// <summary>
        /// Plays an Enter or Exit Animation for the selector
        /// </summary>
        private IEnumerator PlayAnimation(TransformAnimation animTransform, bool Enter)
        {
            if (Enter)                                                      //Enable the controller and UI GAME OBJECTS
            {
                if (Controller)
                {
                    Controller.gameObject.SetActive(true);
                    if (Controller.FocusedItemIndex == -1)
                    {
                        ItemSelected = null;
                    }
                    Controller.enabled = true;                       //Enable the Controller component after the animation.
                    //   StartCoroutine(CheckItemsNextFrame());           //Position all the Items on the default position
                }
                if (UI)
                {
                    UI.UpdateSelectedItemUI(ItemSelected);
                    UI.gameObject.SetActive(true);
                }
            }
            else
            {
            }


            if (animTransform && Target)
            {
                isAnimating = true;

                LastTarget.StoreTransform(Target);


                if (animTransform.delay > 0)
                {
                    yield return(new WaitForSeconds(animTransform.delay));
                }

                float elapsedTime = 0;

                while ((animTransform.time > 0) && (elapsedTime <= animTransform.time))

                {
                    float resultPos = animTransform.PosCurve.Evaluate(elapsedTime / animTransform.time);               //Evaluation of the Pos curve
                    float resultRot = animTransform.RotCurve.Evaluate(elapsedTime / animTransform.time);               //Evaluation of the Rot curve
                    float resultSca = animTransform.ScaleCurve.Evaluate(elapsedTime / animTransform.time);             //Evaluation of the Scale curve

                    if (animTransform.UsePosition)
                    {
                        Target.localPosition =
                            Vector3.LerpUnclamped(LastTarget.LocalPosition, LastTarget.LocalPosition + animTransform.Position, resultPos);
                    }

                    if (animTransform.UseRotation)
                    {
                        Target.localEulerAngles = Vector3.LerpUnclamped(LastTarget.LocalEulerAngles, animTransform.Rotation, resultRot);
                    }

                    if (animTransform.UseScale)
                    {
                        Target.localScale = Vector3.LerpUnclamped(LastTarget.LocalScale, Vector3.Scale(LastTarget.LocalScale, animTransform.Scale), resultSca);
                    }

                    elapsedTime += Time.deltaTime;

                    yield return(null);
                }

                isAnimating = false;
                LastTarget.RestoreLocalTransform(Target);
            }

            if (!Enter)
            {
                if (Controller)
                {
                    Controller.gameObject.SetActive(false);
                    Controller.enabled = false;                      //Disable the Controller component after the animation.
                }
                if (UI)
                {
                    UI.gameObject.SetActive(false);
                }
            }
            else
            {
                if (UI)
                {
                    UI.gameObject.SetActive(true);
                    UI.UpdateSelectedItemUI(ItemSelected);
                }
            }

            yield return(null);
        }
예제 #10
0
        //protected virtual void AddItemCommon(GameObject gameObject)
        //{
        //    gameObject = Instantiate(gameObject, Editor.transform, false);

        //    Editor.UpdateItemsList();                                                       //Update the list!
        //    controller.ResetController();
        //    controller.CheckFirstItemFocus();
        //    LastAddedItem = gameObject.GetComponent<MItem>();
        //}

        /// <summary>
        /// Removes an Item at Runtime using its Mitem script
        /// </summary>
        /// <param name="item">item to remove</param>
        public virtual void _RemoveItem(MItem item)
        {
            RemoveItemCommon(Editor.Items.Find(mitem => mitem == item));
        }
        /// <summary>
        /// Select an item by its MItem Script
        /// </summary>
        public void SelectNextItem(MItem next)
        {
            int index = Items.FindIndex(item => item == next);

            IndexSelected = index;
        }
예제 #12
0
 private void OnEnable()
 {
     M      = (MItem)target;
     script = MonoScript.FromMonoBehaviour((MonoBehaviour)target);
 }