Esempio n. 1
0
 // Use this for initialization
 void Start()
 {
     m_RootRef      = gameObject;
     m_TransformRef = new TransformCache(m_RootRef.transform);
     m_ScaleFactor  = (-m_RootRef.transform.localScale.x) / m_RootRef.transform.localScale.x;
     m_State        = AnimationState.Idle;
 }
Esempio n. 2
0
 // Use this for initialization
 void Start()
 {
     m_RootRef = gameObject;
     m_TransformRef = new TransformCache(m_RootRef.transform);
     m_ScaleFactor = (-m_RootRef.transform.localScale.x) / m_RootRef.transform.localScale.x;
     m_State = AnimationState.Idle;
 }
Esempio n. 3
0
    /// <summary>
    /// Neat initialization method
    /// </summary>
    public override void OnEnable()
    {
        base.OnEnable();

        // Getting needed components
        // Hardcoded names. We have no need of renaming these objects anyway
        _stickTransform = TransformCache.FindChild("Stick").GetComponent <Transform>();
        _baseTransform  = TransformCache.FindChild("Base").GetComponent <Transform>();

        _stickGameObject = _stickTransform.gameObject;
        _baseGameObject  = _baseTransform.gameObject;

        // Initial hiding of we should hide it
        if (IsHiddenIfNotTweaking)
        {
            _baseGameObject.gameObject.SetActive(false);
            _stickGameObject.gameObject.SetActive(false);
        }
        else
        {
            _baseGameObject.gameObject.SetActive(true);
            _stickGameObject.gameObject.SetActive(true);
        }

        TransformCache.localPosition = InitializePosition();
    }
Esempio n. 4
0
        public void IsDescendant_WithNullAncestor_IsFalse()
        {
            m_Transform1.SetParent(m_Transform0);

            TransformCache ancestor = null;

            Assert.IsFalse(m_Transform0.IsDescendant(ancestor), "Null ancestor should return false");
        }
Esempio n. 5
0
    public void ChangeAnimationState(
        int _ChunkIndex,
        AnimationState _NextState,
        float _DelayTime,
        bool _RestoreTransform = true)
    {
        m_TransformRef[_ChunkIndex] = new TransformCache(ChunkRef[_ChunkIndex].transform);
        // m_ScaleFactor = (-m_RootRef.transform.localScale.x) / m_RootRef.transform.localScale.x;
        m_State = _NextState;

        m_NextState = AnimationState.InValid;
        StartCoroutine(PerformChangeAnimationState(_ChunkIndex, _NextState, _DelayTime, _RestoreTransform));
    }
Esempio n. 6
0
    public void ChangeAnimationState(
        int _ChunkIndex,
        AnimationState _NextState, 
        float _DelayTime, 
        bool _RestoreTransform = true)
    {
        m_TransformRef[_ChunkIndex] = new TransformCache(ChunkRef[_ChunkIndex].transform);
        // m_ScaleFactor = (-m_RootRef.transform.localScale.x) / m_RootRef.transform.localScale.x;
        m_State = _NextState;

        m_NextState = AnimationState.InValid;
        StartCoroutine(PerformChangeAnimationState(_ChunkIndex, _NextState, _DelayTime, _RestoreTransform));
    }
Esempio n. 7
0
        public void PlaceOnDropObject(DropObject dropObject)
        {
            TransformCache.SetParent(dropObject.TransformCache);
            TransformCache.localPosition = Vector2.zero;
            isClonning = false;
            if (lastDropObject != null)
            {
                lastDropObject.isEmpty = true;
            }

            dropObject.isEmpty = false;
            lastDropObject     = dropObject;
        }
Esempio n. 8
0
 public static TransformCache Lerp(TransformCache from, TransformCache to, float pt)
 {
     return(new TransformCache()
     {
         m_TransformRef = (pt < .5f) ? from.m_TransformRef : to.m_TransformRef,
         m_AnchorMin = Vector2.Lerp(from.m_AnchorMin, to.m_AnchorMin, pt),
         m_AnchorMax = Vector2.Lerp(from.m_AnchorMax, to.m_AnchorMax, pt),
         m_SizeDelta = Vector2.Lerp(from.m_SizeDelta, to.m_SizeDelta, pt),
         m_Pivot = Vector2.Lerp(from.m_Pivot, to.m_Pivot, pt),
         m_LocalPosition = Vector3.Lerp(from.m_LocalPosition, to.m_LocalPosition, pt),
         m_LocalRotation = Quaternion.Lerp(from.m_LocalRotation, to.m_LocalRotation, pt),
         m_LocalScale = Vector3.Lerp(from.m_LocalScale, to.m_LocalScale, pt)
     });
 }
    private TransformCache CloneTransformCache(VariablesGroup data)
    {
        TransformCache rst = new TransformCache();

        rst.m_LocalPosition = data.localPositionProp.vector3Value;
        rst.m_LocalRotation = data.localRotationProp.quaternionValue;
        rst.m_LocalScale    = data.localScaleProp.vector3Value;
        rst.m_AnchorMin     = data.anchorMinProp.vector2Value;
        rst.m_AnchorMax     = data.anchorMaxProp.vector2Value;
        rst.m_SizeDelta     = data.sizeDeltaProp.vector2Value;
        rst.m_Pivot         = data.pivotProp.vector2Value;
        rst.m_TransformRef  = (TransformCache.eTransformRef)data.tranRefProp.intValue;
        return(rst);
    }
Esempio n. 10
0
        public static Transform FindTransformFromCache(TransformCache cache, string target, bool containsUnActive = false)
        {
            Transform ret;

            cache.Cache.TryGetValue(target, out ret);
            if (containsUnActive)
            {
                return(ret);
            }
            if (null != ret && null != ret.gameObject && !ret.gameObject.activeInHierarchy)
            {
                ret = null;
            }
            return(ret);
        }
Esempio n. 11
0
        private static void CacheTransform(GameObject role, TransformCache transformCache)
        {
            var cache      = transformCache.Cache;
            var transforms = role.GetComponentsInChildren <Transform>(true);

            foreach (Transform transform in transforms)
            {
                if (!cache.ContainsKey(transform.name))
                {
                    cache.Add(transform.name, transform);
                }
                else
                {
                    Logger.InfoFormat("{0} is already in {1} cache", transform.name, role.name);
                }
            }
        }
Esempio n. 12
0
 public void Setup()
 {
     m_Transform0 = CacheObject.Create <TransformCache>(null);
     m_Transform1 = CacheObject.Create <TransformCache>(null);
     m_Transform2 = CacheObject.Create <TransformCache>(null);
 }
Esempio n. 13
0
 /// <summary>
 /// Constructor for the <c>Transformer</c> object. This is
 /// used to create a transformer which will transform specified
 /// types using transforms loaded from the class path. Transforms
 /// are matched to types using the specified matcher object.
 /// </summary>
 /// <param name="matcher">
 /// this is used to match types to transforms
 /// </param>
 public Transformer(Matcher matcher) {
    this.matcher = new DefaultMatcher(matcher);
    this.cache = new TransformCache();
    this.error = new WeakCache();
 }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        property.serializedObject.UpdateIfRequiredOrScript();
        EditorGUI.BeginProperty(position, label, property);
        Rect line = position.Clone(height: EditorGUIUtility.singleLineHeight + singleLine);

        Rect[] left     = line.SplitLeft(80f);
        Rect[] cols     = left[1].SplitLeft(80f);
        Color  orgColor = GUI.color;

        GUI.color = Color.yellow;
        EditorGUI.BeginDisabledGroup(Application.isPlaying);
        EditorGUI.BeginChangeCheck();
        if (GUI.Button(left[0], l_recordButton))
        {
            // We know the propertyPath, let's apply on multiple targets
            string _propertyPath = property.propertyPath;
            for (int i = 0; i < property.serializedObject.targetObjects.Length; i++)
            {
                Component          _component        = (Component)property.serializedObject.targetObjects[i];
                SerializedObject   _serializedObject = new SerializedObject(_component);
                SerializedProperty _property         = _serializedObject.FindProperty(_propertyPath);
                VariablesGroup     _data             = new VariablesGroup(_property);
                Undo.RecordObjects(new[] { _component, _component.transform }, "Record Transform");
                _data.localPositionProp.vector3Value = _component.transform.localPosition;
                if (_component.transform is RectTransform)
                {
                    RectTransform obj = (RectTransform)_component.transform;
                    _data.anchorMinProp.vector2Value     = obj.anchorMin;
                    _data.anchorMaxProp.vector2Value     = obj.anchorMax;
                    _data.sizeDeltaProp.vector2Value     = obj.sizeDelta;
                    _data.pivotProp.vector2Value         = obj.pivot;
                    _data.localPositionProp.vector3Value = obj.anchoredPosition3D;
                }
                _data.localRotationProp.quaternionValue = _component.transform.localRotation;
                _data.localScaleProp.vector3Value       = _component.transform.localScale;
                _property.serializedObject.ApplyModifiedProperties();

                InvokeMethod(
                    _component,
                    TransformCache.Editor_Record_Callback,
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                    new[] { _propertyPath });
            }
        }
        GUI.color = Color.green;
        if (GUI.Button(cols[0], l_AssignButton))
        {
            // We know the propertyPath, let's apply on multiple targets
            string _propertyPath = property.propertyPath;
            for (int i = 0; i < property.serializedObject.targetObjects.Length; i++)
            {
                Component          _component        = (Component)property.serializedObject.targetObjects[i];
                SerializedObject   _serializedObject = new SerializedObject(_component);
                SerializedProperty _property         = _serializedObject.FindProperty(_propertyPath);
                TransformCache     cache             = CloneTransformCache(new VariablesGroup(_property));

                Undo.RecordObjects(new[] { _component, _component.transform }, "Load Transform");
                cache.AssignTo(_component.transform);
                _property.serializedObject.ApplyModifiedProperties();

                InvokeMethod(
                    _component,
                    TransformCache.Editor_Load_Callback,
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                    new[] { _propertyPath });
            }
        }
        if (EditorGUI.EndChangeCheck() && !Application.isPlaying)
        {
            EditorUtility.SetDirty(property.serializedObject.targetObject);
        }
        EditorGUI.EndDisabledGroup();

        VariablesGroup data      = new VariablesGroup(property);
        Component      component = (Component)property.serializedObject.targetObject;

        GUI.color           = orgColor;
        property.isExpanded = EditorGUI.Foldout(cols[1].Adjust(x: 15f).Clone(width: 50f), property.isExpanded, l_Detail, true);
        TransformCache.eTransformRef tranRef = (TransformCache.eTransformRef)data.tranRefProp.enumValueIndex;

        if (property.isExpanded)
        {
            if (component.transform is RectTransform)
            {
                RectTransform rectTran = (RectTransform)component.transform;
                line = line.GetRectBottom(height: singleLine);
                DrawRectButton(line, data.tranRefProp,
                               TransformCache.eTransformRef.AnchorMin, data.anchorMinProp,
                               () => { data.anchorMinProp.vector2Value = rectTran.anchorMin; });

                line = line.GetRectBottom(height: singleLine);
                DrawRectButton(line, data.tranRefProp,
                               TransformCache.eTransformRef.AnchorMax, data.anchorMaxProp,
                               () => { data.anchorMaxProp.vector2Value = rectTran.anchorMax; });

                line = line.GetRectBottom(height: singleLine);
                DrawRectButton(line, data.tranRefProp,
                               TransformCache.eTransformRef.SizeDelta, data.sizeDeltaProp,
                               () => { data.sizeDeltaProp.vector2Value = rectTran.sizeDelta; });


                line = line.GetRectBottom(height: singleLine);
                DrawRectButton(line, data.tranRefProp,
                               TransformCache.eTransformRef.Pivot, data.pivotProp,
                               () => { data.pivotProp.vector2Value = rectTran.pivot; });
            }

            // position
            line = line.GetRectBottom(height: singleLine);
            DrawRectButton(line, data.tranRefProp,
                           TransformCache.eTransformRef.LocalPosition, data.localPositionProp,
                           () => {
                if (component.transform is RectTransform)
                {
                    data.localPositionProp.vector3Value = ((RectTransform)component.transform).anchoredPosition3D;
                }
                else
                {
                    data.localPositionProp.vector3Value = component.transform.localPosition;
                }
            });

            // rotation
            line = line.GetRectBottom(height: singleLine);
            DrawRectButton(line, data.tranRefProp,
                           TransformCache.eTransformRef.LocalRotation, data.localRotationProp,
                           () => { data.localRotationProp.quaternionValue = component.transform.localRotation; },
                           DrawQuaternionParam);
            // TODO:
            // Vector3 rotate = EditorGUI.Vector3Field(cols[1], l_LocalRotation, data.localRotationProp.quaternionValue.eulerAngles);
            //	data.localRotationProp.quaternionValue = Quaternion.Euler(rotate);

            // scale
            line = line.GetRectBottom(height: singleLine);
            DrawRectButton(line, data.tranRefProp,
                           TransformCache.eTransformRef.LocalScale, data.localScaleProp,
                           () => { data.localScaleProp.vector3Value = component.transform.localScale; });
        }

        EditorGUI.EndProperty();
    }
Esempio n. 15
0
 protected virtual void UpdateCache()
 {
     cacheTr = new TransformCache(transform);
 }