Exemplo n.º 1
0
        public static IEnumerator SetLocalRotationCoroutine(this Transform trans, Quaternion target, float timer)
        {
            Quaternion init = trans.localRotation;

            float coveredTime = 0;

            while (coveredTime < timer)
            {
                yield return(new WaitForEndOfFrame());

                coveredTime += Time.deltaTime;
                float frac = coveredTime / timer;
                trans.localRotation = Quaternion.Slerp(init, target, frac);
            }
            trans.localRotation = target;

            PTTransform ptTransform = trans.GetComponent <PTTransform>();

            if (ptTransform)
            {
                if (ptTransform.OnRotated != null)
                {
                    ptTransform.OnRotated();
                }
            }
        }
Exemplo n.º 2
0
        static void CreateTable(MenuCommand menuCommand)
        {
            // Create a custom game object
            PTTransform obj = GameObject.CreatePrimitive(PrimitiveType.Cube).AddComponent <PTTransform>();

            obj.name = "object";
            // Ensure it gets reparented if this was a context click (otherwise does nothing)
            GameObjectUtility.SetParentAndAlign(obj.gameObject, menuCommand.context as GameObject);
            // Register the creation in the undo system
            Undo.RegisterCreatedObjectUndo(obj, "Create " + obj.name);
            Selection.activeObject = obj;
        }
Exemplo n.º 3
0
        private void OnTransformParentChanged()
        {
            PTZone parentZone = GetComponentInParent <PTZone>();

            if (parentZone)
            {
                foreach (Transform child in parentZone.content)
                {
                    PTTransform ptTrans = child.GetComponent <PTTransform>();
                    if (ptTrans && ptTrans.OnSiblingChanged != null)
                    {
                        ptTrans.OnSiblingChanged(parentZone);
                    }
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// The behavior of adding object to hand
 /// </summary>
 /// <param name="hand"></param>
 protected virtual void AddToHand(PTTransform hand)
 {
     this.hand.Add(hand.transform, PT.DEFAULT_TIMER);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Get the target local position in arrangement
        /// </summary>
        /// <param name="siblingIndex"> The given sibling index </param>
        /// <returns></returns>
        public Vector3 TargetLocalPositionOf(int siblingIndex)
        {
            siblingIndex = siblingIndex > 0 ? siblingIndex : 0;
            siblingIndex = siblingIndex < Count ? siblingIndex : Count - 1;

            //Get valid count id limits
            int validCountOfLimits = 0;

            foreach (int i in dimensionLimits)
            {
                if (i <= 0)
                {
                    break;
                }
                validCountOfLimits++;
            }

            //Get dimension
            int totalDimension = validCountOfLimits < dimensionSpacings.Length ?
                                 validCountOfLimits + 1 : dimensionSpacings.Length;

            //Adjust sibling index by extra spacing
            int totalCountExtraSpacing = 0;

            for (int i = 0; i <= siblingIndex; ++i)
            {
                PTTransform currTrans = Get(i).GetComponent <PTTransform>();
                if (currTrans)
                {
                    totalCountExtraSpacing += currTrans.countExtraSpacing;
                }
            }
            int adjustedSiblingIndex = siblingIndex + totalCountExtraSpacing;

            //Get total offset
            Vector3 offset = Vector3.zero;

            for (int dimension = 0; dimension < totalDimension; dimension++)
            {
                //Get maxLowerDimension
                int capacityLowerDimension = 1;
                for (int j = 0; j < dimension; j++)
                {
                    capacityLowerDimension *= dimensionLimits[j];
                }

                //Calculate offset
                int indexInCurrDimension = (adjustedSiblingIndex / capacityLowerDimension) %
                                           (totalDimension - dimension > 1 ? dimensionLimits[dimension] : Int32.MaxValue);

                int currTotalLowerIncludesDimension = CurrTotalLowerIncludes(dimension);
                int capacityLowerExcludesDimension  = CapacityLowerExcludes(dimension);
                int totalInTheSameDimension         = capacityLowerExcludesDimension == 0 ? currTotalLowerIncludesDimension : currTotalLowerIncludesDimension / capacityLowerExcludesDimension + (currTotalLowerIncludesDimension % capacityLowerExcludesDimension > 0 ? 1: 0);
                //Debug.Log("capacityLowerExcludesDimension=" + capacityLowerExcludesDimension + " totalInTheSameDimension=" + totalInTheSameDimension);

                //+ currTotalLowerIncludesDimension % capacityLowerExcludesDimension == 0 ? 0 : 1;
                //Debug.Log(" totalInTheSameDimension=" + totalInTheSameDimension);


                /*Debug.Log(name
                 + " indexInCurrDimension=" + indexInCurrDimension
                 + " totalInTheSameDimension=" + totalInTheSameDimension
                 + " CurrTotalLowerIncludes(dimension)" + CurrTotalLowerIncludes(dimension)
                 + " CapacityLowerExcludes(dimension)" + CapacityLowerExcludes(dimension)
                 +  );
                 */
                Vector3 currSpacing = dimensionSpacings.Length > dimension ? dimensionSpacings[dimension] : Vector3.zero;
                offset += GetIncreaseSpacing(IsSymmetricOnDimension(dimension), currSpacing, indexInCurrDimension, totalInTheSameDimension, dimension);
            }

            //Target local position
            return(firstChildLocalPosition + offset);
        }