예제 #1
0
    /// <summary>
    /// Remove the origamiObject of the room, and add it in the selectable objects list.
    /// </summary>
    /// <param name="origamiObject">Origami object.</param>
    public bool Collect(OrigamiObject origamiObject)
    {
        if (this.nbObjects < this.maxSize)
        {
            // Find index of the first hole
            int idx = 0;
            foreach (OrigamiObject obj in this._selectableObjects)
            {
                if (obj == null)
                {
                    break;
                }
                ++idx;
            }

            this._selectableObjects[idx]   = origamiObject;
            origamiObject.transform.parent = this.player.transform;
            origamiObject.gameObject.SetActive(false);

            this.nbObjects++;
            return(true);
        }

        return(false);
    }
예제 #2
0
 public void AssembleReplaceInAssembleArea(OrigamiObject replacedOrigamiObject1, OrigamiObject replacedOrigamiObject2, OrigamiObject newOrigamiObject)
 {
     this._assembleAreaObjects.Remove(replacedOrigamiObject1);
     this._assembleAreaObjects.Remove(replacedOrigamiObject2);
     this._assembleAreaObjects.AddLast(newOrigamiObject);
     this.nbObjects -= 1;
 }
예제 #3
0
    /// <summary>
    /// Move the origamiObject in assemble area list and remove it of selectable Objects list.
    /// </summary>
    /// <param name="origamiObject">Origami object.</param>
    public void MoveInAssembleArea(OrigamiObject origamiObject)
    {
        int idx = Array.IndexOf(this._selectableObjects, origamiObject);

        this._selectableObjects[idx] = null;
        this._assembleAreaObjects.AddLast(origamiObject);
    }
예제 #4
0
    public void MoveDraggedObjectToSlot(int slotIndex)
    {
        int           draggedIndex  = this._draggedSlot.transform.parent.GetComponent <InventorySlot> ().slotIndex;
        OrigamiObject origamiToMove = this._draggedSlot.GetComponentInChildren <OrigamiObject> ();

        this.RemoveObjectFormInventorySlot(draggedIndex);
        this.AddObjectToInventorySlot(origamiToMove, slotIndex, false);
        this._draggedSlot.GetComponent <DraggableZone> ().selected = false;
        this.isDragging = false;
        this.inventorySlots [slotIndex].GetComponent <InventoryIdleAnimation> ().StopRotation();
        this.inventorySlots [slotIndex].GetComponent <InventoryIdleAnimation> ().inPlace = false;

        // Deal with the case of moving the selected object
        if (this._draggedSlot.transform.parent.GetComponent <InventorySlot> () == selectedSlot)
        {
            this.inventorySlots[slotIndex].transform.parent.parent.GetComponent <InventorySlot>().Select();
            this.inventory.SwitchPositionInSelectableArea(draggedIndex, slotIndex);
            this.inventory.selectByIndex(slotIndex);
        }

        // Put the slot back to it's position
        this._draggedSlot.transform.localPosition = Vector3.zero;
        this._draggedSlot.transform.GetChild(0).GetComponent <InventoryIdleAnimation>().isDragged = false;
        this._draggedSlot.transform.GetChild(0).GetComponent <InventoryIdleAnimation> ().ResumeRotation();
        this._draggedSlot = null;
    }
예제 #5
0
    void AddObjectToInventorySlot(OrigamiObject origami, int slotIndex, bool resetPosition = true)
    {
        GameObject origamiGameObject = origami.gameObject;
        Transform  currentSlot       = this.inventorySlots [slotIndex];

        origamiGameObject.transform.parent = currentSlot;
        origamiGameObject.gameObject.SetActive(true);
        if (resetPosition)
        {
            origamiGameObject.transform.localPosition = Vector3.zero;
        }
        origamiGameObject.transform.localRotation = Quaternion.identity;

        Vector3 origamiBounds = origami.GetBounds().extents;
        float   maxBound      = Mathf.Max(origamiBounds.x, origamiBounds.y, origamiBounds.z);

        maxBound = maxBound == 0 ? undefinedScale : maxBound;
        float scaleFactor = this.slotSize / maxBound;

        currentSlot.localScale = scaleFactor * Vector3.one;

        currentSlot.GetComponent <InventoryIdleAnimation>().isRotating = true;

        //origamiGameObject.gameObject.layer = (5);
        SetLayerRecursively(origamiGameObject, 5);
    }
예제 #6
0
 public override OrigamiObject Add(OrigamiObject origamiObject)
 {
     if (origamiObject != null)
     {
         LinkedList <OrigamiObject> origamiObjectsToAdd = new LinkedList <OrigamiObject> ();
         if (origamiObject.GetType() == typeof(AssembledOrigamiObject))
         {
             foreach (OrigamiObject origObj in this.origamiObjects)
             {
                 origamiObjectsToAdd.AddLast(origObj);
             }
             this.destroy = true;
         }
         else
         {
             origamiObjectsToAdd.AddLast(origamiObject);
         }
         foreach (OrigamiObject origamiObjectToAdd in origamiObjectsToAdd)
         {
             this.origamiObjects.AddLast(origamiObjectToAdd);
             origamiObjectToAdd.transform.parent = this.transform;
             if (origamiObjectToAdd.GetBaseAnchorPoint() != null)
             {
                 this.origamiBaseObject = origamiObject;
             }
         }
     }
     return(this);
 }
예제 #7
0
    /// <summary>
    /// Switch the elements at specific indexes in selectable area.
    /// </summary>
    /// <param name="oldIdx">Old index.</param>
    /// <param name="newIdx">New index.</param>
    public void SwitchPositionInSelectableArea(int oldIdx, int newIdx)
    {
        OrigamiObject obj  = this._selectableObjects [oldIdx];
        OrigamiObject obj2 = this._selectableObjects [newIdx];

        this._selectableObjects[newIdx] = obj;
        this._selectableObjects[oldIdx] = obj2;
    }
예제 #8
0
 public Inventory(int maxSize, Player player)
 {
     this.player               = player;
     this.maxSize              = maxSize;
     this.nbObjects            = 0;
     this._selectedObject      = null;
     this.selectedIndex        = 0;
     this._selectableObjects   = new OrigamiObject[maxSize];
     this._assembleAreaObjects = new LinkedList <OrigamiObject> ();
     this.heldObjectContainer  = GameObject.Find("HeldObjectContiner").transform;
 }
예제 #9
0
    public bool Put(OrigamiObject origamiObject)
    {
        AnchorPoint baseAnchorPoint = origamiObject.GetBaseAnchorPoint();

        if (baseAnchorPoint != null && validBaseObject.name == baseAnchorPoint.transform.parent.name)
        {
            this._isActivated = true;
            for (int i = 0; i < actions.Length; ++i)
            {
                ObjectAction action = actions [i];
                if (action != null)
                {
                    action.Action(1);
                }
            }
            // Avoid collect
            if (this.makeInteractive)
            {
                this.gameObject.tag = "InteractiveObject";
            }
            origamiObject.SetValid();
            origamiObject.SetFinalMaterial();

            // Code here the animation to "assemble" targetPoint and anchorPoint

            Matrix4x4 transforMatrix1 = Matrix4x4.TRS(Vector3.zero, baseAnchorPoint.transform.rotation, Vector3.one);
            Matrix4x4 transforMatrix2 = Matrix4x4.TRS(Vector3.zero, this.targetPoint.transform.rotation, Vector3.one);

            Vector3 realNormal1 = transforMatrix1.MultiplyPoint3x4(baseAnchorPoint.normal.normalized);
            Vector3 realNormal2 = transforMatrix2.MultiplyPoint3x4(this.targetPoint.normal.normalized);

            origamiObject.transform.rotation = Quaternion.FromToRotation(realNormal1, -realNormal2) * origamiObject.transform.rotation;

            transforMatrix1 = Matrix4x4.TRS(Vector3.zero, baseAnchorPoint.transform.rotation, Vector3.one);
            transforMatrix2 = Matrix4x4.TRS(Vector3.zero, this.targetPoint.transform.rotation, Vector3.one);

            Vector3 realUp1 = transforMatrix1.MultiplyPoint3x4(baseAnchorPoint.directionUp.normalized);
            Vector3 realUp2 = transforMatrix2.MultiplyPoint3x4(this.targetPoint.directionUp.normalized);

            origamiObject.transform.rotation = Quaternion.FromToRotation(realUp1, realUp2) * origamiObject.transform.rotation;

            Vector3 realAnchorPos1 = (baseAnchorPoint.transform.position - origamiObject.transform.position);
            Vector3 realAnchorPos2 = (this.targetPoint.transform.position - this.transform.position);

            origamiObject.transform.position = this.transform.position + realAnchorPos2 - realAnchorPos1;

            origamiObject.transform.parent = this.transform;
            foreach (Transform child in gameObject.GetComponentsInChildren <Transform>(true))
            {
                child.gameObject.layer = 0;
            }
        }
        return(this._isActivated);
    }
예제 #10
0
    public virtual OrigamiObject Add(OrigamiObject origamiObject)
    {
        if (origamiObject != null)
        {
            // Debug.Log (origamiObject.GetType ());
            if (origamiObject.GetType() == typeof(AssembledOrigamiObject))
            {
                return(origamiObject.Add(this));
            }
            else
            {
                Object obj = Resources.Load("AssembledOrigamiObject", typeof(GameObject));

                GameObject             gameObject             = Instantiate(obj) as GameObject;
                AssembledOrigamiObject assembledOrigamiObject = gameObject.GetComponent <AssembledOrigamiObject> ();
                assembledOrigamiObject.transform.parent = this.transform.parent;
                assembledOrigamiObject.Add(this);
                assembledOrigamiObject.Add(origamiObject);
                return(assembledOrigamiObject);
            }
        }
        return(null);
    }
예제 #11
0
    private void DropResolve()
    {
        if (this.drop)
        {
            this.drop = false;
            OrigamiObject selectedObject = this._inventory.selectedObject;
            if (selectedObject == null)
            {
                return;
            }

            if (!selectedObject.IsFinalObject())
            {
                this.heldObjectContiner.StartErrorState();
                Debug.Log("non valide");
            }
            else
            {
                RaycastHit hit;
                if (Physics.Raycast(this.eyeCamera.transform.position, this.eyeCamera.transform.forward, out hit, this.interactionDistance))
                {
                    if (hit.collider.gameObject.tag == "TargetObject")
                    {
                        TargetObject targetObject = hit.collider.gameObject.GetComponent <TargetObject> ();
                        if (targetObject.Put(selectedObject))
                        {
                            this._inventory.DropSelected();
                        }
                        else
                        {
                            this.heldObjectContiner.StartErrorState();
                        }
                    }
                }
            }
        }
    }
예제 #12
0
 /// <summary>
 /// Remove replacedOrigamiObject and add the newOrigamiObjects. Use this function when you disassemble objects.
 /// </summary>
 /// <param name="replacedOrigamiObject">Replaced origami object.</param>
 /// <param name="newOrigamiObject">LinkedListNode of new origami objects</param>
 public void DisassembleReplaceInAssembleArea(LinkedList <OrigamiObject> newOrigamiObjects, OrigamiObject replacedOrigamiObject)
 {
     this._assembleAreaObjects.Remove(replacedOrigamiObject);
     foreach (OrigamiObject obj in newOrigamiObjects)
     {
         this._assembleAreaObjects.AddLast(obj);
     }
     this.nbObjects += newOrigamiObjects.Count - 1;
 }
예제 #13
0
 /// <summary>
 /// Remove replacedOrigamiObjects and add the newOrigamiObject. Use this function when you assemble objects.
 /// </summary>
 /// <param name="replacedOrigamiObjects">LinkedListNode of replaced origami objects.</param>
 /// <param name="newOrigamiObject">New origami object</param>
 public void AssembleReplaceInAssembleArea(LinkedList <OrigamiObject> replacedOrigamiObjects, OrigamiObject newOrigamiObject)
 {
     foreach (OrigamiObject obj in replacedOrigamiObjects)
     {
         this._assembleAreaObjects.Remove(obj);
     }
     this._assembleAreaObjects.AddLast(newOrigamiObject);
     this.nbObjects -= replacedOrigamiObjects.Count + 1;
 }
예제 #14
0
 /// <summary>
 /// Move the origamiObject in selectable objects list and removeit of assemble Area list.
 /// </summary>
 /// <param name="origamiObject">Origami object.</param>
 public void MoveInSelectableArea(OrigamiObject origamiObject, int index)
 {
     this._assembleAreaObjects.Remove(origamiObject);
     this._selectableObjects[index] = origamiObject;
 }
예제 #15
0
    public void ConnectAnchors(AnchorPoint anchor)
    {
        if (anchor == null || this.selectedAnchor == null || this.selectedAnchor.GetComponentInParent <RotateByDragging>().Equals(anchor.GetComponentInParent <RotateByDragging>()))
        {
            return;
        }
        Transform object1          = this.selectedAnchor.transform.parent;
        Transform object2          = anchor.transform.parent;
        Transform simpleObject1    = object1;
        Transform simpleObject2    = object2;
        bool      object1Assembled = false;
        bool      object2Assembled = false;

        object1.GetComponent <OrigamiObject> ().connectedAnchors.AddLast(anchor);
        object2.GetComponent <OrigamiObject> ().connectedAnchors.AddLast(this.selectedAnchor);

        if (object1.GetComponentInParent <AssembledOrigamiObject> ())
        {
            object1 = object1.GetComponentInParent <AssembledOrigamiObject> ().transform;
            //Debug.Log ("1 is assembled");
            object1Assembled = true;
        }
        if (object2.GetComponentInParent <AssembledOrigamiObject> ())
        {
            object2 = object2.GetComponentInParent <AssembledOrigamiObject> ().transform;
            //Debug.Log ("2 is assembled");
            object2Assembled = true;
        }

        Matrix4x4 transforMatrix1 = Matrix4x4.TRS(Vector3.zero, this.selectedAnchor.transform.rotation, Vector3.one);
        Matrix4x4 transforMatrix2 = Matrix4x4.TRS(Vector3.zero, anchor.transform.rotation, Vector3.one);

        Vector3 realNormal1 = transforMatrix1.MultiplyPoint3x4(this.selectedAnchor.normal.normalized);
        Vector3 realNormal2 = transforMatrix2.MultiplyPoint3x4(anchor.normal.normalized);

        if (true)
        {
            object1.parent.rotation = Quaternion.FromToRotation(realNormal1, -realNormal2) * object1.parent.rotation;
        }
        else
        {
            object1.parent.rotation = Quaternion.FromToRotation(this.selectedAnchor.normal.normalized, -realNormal2);
        }

        transforMatrix1 = Matrix4x4.TRS(Vector3.zero, this.selectedAnchor.transform.rotation, Vector3.one);
        transforMatrix2 = Matrix4x4.TRS(Vector3.zero, anchor.transform.rotation, Vector3.one);

        Vector3 realUp1 = transforMatrix1.MultiplyPoint3x4(this.selectedAnchor.directionUp.normalized);
        Vector3 realUp2 = transforMatrix2.MultiplyPoint3x4(anchor.directionUp.normalized);

        object1.parent.rotation = Quaternion.FromToRotation(realUp1, realUp2) * object1.parent.rotation;

        Vector3 realAnchorPos1 = (this.selectedAnchor.transform.position - object1.parent.position);
        Vector3 realAnchorPos2 = (anchor.transform.position - object2.parent.position);

        object1.parent.position = object2.parent.position + realAnchorPos2 - realAnchorPos1;

        Transform oldRotater1 = object1.GetComponentInParent <RotateByDragging>().transform;
        Transform oldRotater2 = object2.GetComponentInParent <RotateByDragging>().transform;

        this.selectedAnchor.LinkTo(anchor);
        OrigamiObject assembled = object1.GetComponent <OrigamiObject> ().Add(object2.GetComponent <OrigamiObject> ());

        this.inventory.AssembleReplaceInAssembleArea(object1.GetComponent <OrigamiObject> (), object2.GetComponent <OrigamiObject> (), assembled);
        AssembledOrigamiObject realAssembled = (AssembledOrigamiObject)assembled;

        /*if (oldRotater1.childCount <= 0) {
         *      this.assembleObjs.Remove (oldRotater1);
         *      Destroy (oldRotater1.gameObject);
         * } else if (oldRotater2.GetChild(0) <= 0) {
         *      this.assembleObjs.Remove (oldRotater2);
         *      Destroy (oldRotater2.gameObject);
         * } else {
         *      Debug.Log ("ERROR ASSEMBLING "+"("+oldRotater1.GetChild(0).childCount+" ; "+oldRotater2.GetChild(0).childCount+")");
         * }*/

        if (oldRotater1.childCount <= 0)
        {
            this.assembleObjs.Remove(oldRotater1);
            Destroy(oldRotater1.gameObject);
        }
        else if (oldRotater1.GetChild(0).childCount == 0)
        {
            this.assembleObjs.Remove(oldRotater1);
            Destroy(oldRotater1.gameObject);
        }
        if (oldRotater2.childCount <= 0)
        {
            this.assembleObjs.Remove(oldRotater2);
            Destroy(oldRotater2.gameObject);
        }
        else if (oldRotater2.GetChild(0).childCount == 0)
        {
            this.assembleObjs.Remove(oldRotater2);
            Destroy(oldRotater2.gameObject);
        }

        this.selectedAnchor.Deselect();
        this.selectedAnchor = null;

        Vector3[] oldPositions = new Vector3[assembled.transform.childCount];
        Vector3   barycenter   = Vector3.zero;

        for (int i = 0; i < assembled.transform.childCount; ++i)
        {
            oldPositions [i] = assembled.transform.GetChild(i).position;
            barycenter      += assembled.transform.GetChild(i).position / assembled.transform.childCount;
        }
        assembled.transform.parent.position = barycenter;
        assembled.transform.localPosition   = Vector3.zero;
        for (int i = 0; i < assembled.transform.childCount; ++i)
        {
            assembled.transform.GetChild(i).position = oldPositions [i];
        }

        realAssembled.ComputeNewBounds();

        //Resize the rotater
        Vector3 origamiBounds = realAssembled.GetBounds().extents;
        float   maxBound      = Mathf.Max(origamiBounds.x, origamiBounds.y, origamiBounds.z);

        maxBound = maxBound == 0 ? undefinedScale : maxBound;
        float scaleFactor = this.assembleSize / maxBound;

        assembled.transform.parent.GetComponent <RotateByDragging> ().maxScale = scaleFactor;

        if (this.inventory.NumberAssembleAreaObjects() == 1)
        {
            this.assembleObjScale = scaleFactor;
        }
        else if (scaleFactor < this.assembleObjScale)
        {
            this.assembleObjScale = scaleFactor;
        }

        this.UpdateAssembleObjScale();
    }