Exemplo n.º 1
0
        public void Init(Animator animator)
        {
            _renderers = _propRoot.GetComponentsInChildren <Renderer>();

            if (_animClip != null)
            {
                _animation = _propRoot.gameObject.GetComponent <Animation>();
                if (_animation == null)
                {
                    _animation = _propRoot.gameObject.AddComponent <Animation>();
                }

                if (!_animation.GetClip(_animClip.name))
                {
                    _animation.AddClip(_animClip, _animClip.name);
                }
            }

            if (_attachToBone)
            {
                Transform attachment = MoveEditor.MoveUtils.GetBodyPartTransform(animator, _attachment);
                _propRoot.position = attachment.position;
                _propRoot.rotation = attachment.rotation;
                AttachTransform.Attach(_propRoot.gameObject, attachment);
            }
        }
Exemplo n.º 2
0
    public static AttachTransform Attach(GameObject target, Transform attachment, bool flipped, bool lockRotation, bool lockX = false, HeightLock lockY = HeightLock.Unlocked, bool lockZ = false)
    {
        AttachTransform at = target.GetComponent <AttachTransform>();

        if (at == null)
        {
            at = target.AddComponent <AttachTransform>();
        }

        // Note: Ideally child rot and child position should be passed in, and not recalculated by applying the inverses. It's unnecessary.

        at._attachment              = attachment;
        at._startChildRotation      = Quaternion.Inverse(attachment.rotation) * target.transform.rotation;
        at._startChildPosition      = attachment.InverseTransformPoint(target.transform.position);
        at._startChildWorldPosition = target.transform.position;
#if UNITY_EDITOR
        at._attached = true;
#endif
        at._flipped      = flipped;
        at._lockRotation = lockRotation;
        at._lockXOffset  = lockX;
        at._lockYOffset  = lockY;
        at._lockZOffset  = lockZ;

        at.UpdateAttachment();

        return(at);
    }
Exemplo n.º 3
0
 public void SetAtHitPoint(Vector3 hitPoint)
 {
     if (_particleSystem != null && _properties != null)
     {
         AttachTransform.Detach(_particleSystem.gameObject);
         _particleSystem.transform.position = hitPoint;
     }
 }
Exemplo n.º 4
0
    public void Recycle(GameObject go)
    {
        if (_active.Contains(go))
        {
            AttachTransform.Detach(go);

            _ready.Add(go);
            _active.Remove(go);
            go.transform.SetParent(GenericPoolSingleton.Instance.transform);
        }
    }
Exemplo n.º 5
0
    private void OnParticleFieldAdd(MoveEditor.ParticleEventProperties properties, ParticleSystem ps, bool flipped)
    {
        CleanUpPreviewParticle();

        if (ps != null && _previewGameObject != null)
        {
            _previewParticleSystem = MoveEditor.MoveUtils.InstantiateParticle(this, properties, GetAnimator(), flipped, true);
            if (_previewParticleSystem != null)
            {
                AttachTransform.Detach(_previewParticleSystem.gameObject);
                _previewParticleSystem.transform.parent = MoveEditor.MoveUtils.GetBodyPartTransform(GetAnimator(), properties._bodyPart, properties._attachmentPath);
                Selection.activeTransform = _previewParticleSystem.transform;
            }
        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// 清除掉对象上挂载的组件
    /// </summary>
    /// <param name="target">对像</param>
    public static void Detach(GameObject target)
    {
        AttachTransform at = target.GetComponent <AttachTransform>();

        if (at != null)
        {
            if (Application.isPlaying)
            {
                Destroy(at);
            }
            else
            {
                DestroyImmediate(at);
            }
        }
    }
Exemplo n.º 7
0
    // TJ: Use this if we only want to lock the position of the thing as it moves, but not use the attach logic to position it
    public static AttachTransform LockPosition(GameObject target, bool lockX = false, HeightLock lockY = HeightLock.Unlocked, bool lockZ = false)
    {
        AttachTransform at = target.GetComponent <AttachTransform>();

        if (at == null)
        {
            at = target.AddComponent <AttachTransform>();
        }

        at._attachment = null;
        at._startChildWorldPosition = target.transform.position;
        at._lockXOffset             = lockX;
        at._lockYOffset             = lockY;
        at._lockZOffset             = lockZ;

        return(at);
    }
Exemplo n.º 8
0
    // Shut down all systems
    public void Retire()
    {
        for (int i = _active.Count - 1; i >= 0; --i)
        {
            if (_active[i] != null)
            {
                U tri = _active[i].GetComponent <U>();
                tri.Stop();

                AttachTransform.Detach(_active[i]);

                _active[i].transform.SetParent(GenericPoolSingleton.Instance.transform);
                _ready.Add(_active[i]);
            }
            _active.RemoveAt(i);
        }
    }
Exemplo n.º 9
0
    public void Update()
    {
        for (int i = _active.Count - 1; i >= 0; --i)
        {
            if (_active[i] == null)
            {
                continue;
            }
            U tri = _active[i].GetComponent <U>();
            if (tri != null && !tri.IsPlaying)
            {
                AttachTransform.Detach(_active[i]);

                _ready.Add(_active[i]);
                _active[i].transform.SetParent(GenericPoolSingleton.Instance.transform);
                _active.RemoveAt(i);
            }
        }
    }
Exemplo n.º 10
0
        public static GameObject InstantiateDynamicLight(DynamicLightEventProperties properties, Animator animator, bool flipped, bool bypassPools = false)
        {
            GameObject light = null;

            if (Application.isPlaying)
            {
                if (!bypassPools)
                {
                    light = LoadLightWithPool(properties);
                }
                else
                {
                    light = LoadLightWithoutPool(properties);
                }
            }
            else
            {
                light = LoadLightWithoutPool(properties);
            }


            if (light != null)
            {
                //DynamicPointLightInstance lightInstance = light.GetComponent<DynamicPointLightInstance>();

                if (animator != null)
                {
                    light.transform.parent        = GetBodyPartTransform(animator, properties._attachment, properties._attachmentPath);
                    light.transform.localPosition = properties._offset;
                }

                if (properties._parent)
                {
                    AttachTransform.Attach(light, light.transform.parent, flipped, false);
                }
            }

            return(light);
        }
Exemplo n.º 11
0
        public static GameObject InstantiateTrailInstance(TrailRendererEventProperties properties, Animator animator, bool flipped, bool isCrit, bool bypassPools = false)
        {
            GameObject trail = null;

            if (Application.isPlaying)
            {
                if (!bypassPools)
                {
                    trail = LoadTrailWithPool(properties, isCrit);
                }
                else
                {
                    trail = LoadTrailWithoutPool(properties, isCrit);
                }
            }
            else
            {
                trail = LoadTrailWithoutPool(properties, isCrit);
            }

            if (trail != null)
            {
                TrailRendererInstance tri    = trail.GetComponent <TrailRendererInstance>();
                Transform             parent = null;

                if (tri != null)
                {
                    Vector3 offset1 = properties._offset1;
                    Vector3 offset2 = properties._offset2;

                    tri.OffsetPoints(offset1, offset2, properties._useLocalOffsets);

                    if (tri._TimeUnits == TrailRenderer.eTIME_UNITS.Frames)
                    {
                        tri.ConvertFramesToSeconds(properties._fps);
                    }
                }

                if (animator != null)
                {
                    parent = GetBodyPartTransform(animator, properties._attachment, properties._attachmentPath);
                    trail.transform.parent = parent;

                    trail.transform.localPosition = properties._rigOffset;

                    if (properties._worldSpace)
                    {
                        trail.transform.eulerAngles = properties._angles;

                        if (flipped)
                        {
                            // rotate this by 180
                            trail.transform.RotateAround(trail.transform.position, Vector3.up, 180.0f);
                        }
                    }
                    else
                    {
                        trail.transform.localEulerAngles = properties._angles;
                    }
                }

                trail.transform.localScale = Vector3.one;

                if (!properties._parent)
                {
                    trail.transform.parent = null;
                }
                else
                {
                    AttachTransform at = AttachTransform.LockPosition(trail, properties._lockXOffset, properties._lockYOffset, properties._lockZOffset);
                    tri.SetAttachTransform(at);
                }
            }

            return(trail);
        }
Exemplo n.º 12
0
        public static ParticleSystem InstantiateParticle(Object obj, ParticleEventProperties properties, Animator animator, bool flipped = false, bool bypassPools = false)
        {
            ParticleSystem ps = GetParticleInstance(obj, properties, flipped, bypassPools);

            if (ps != null)
            {
                Transform parent = GetBodyPartTransform(animator, properties._bodyPart, properties._attachmentPath);

                if (properties._parent)
                {
                    ps.transform.SetParent(parent);
                    if (properties._bodyPart == BodyPart.HeadNubNotRot)
                    {
                        ps.transform.position         = animator.GetComponent <FXHelper>().HeadNubTransform.position;
                        ps.transform.localEulerAngles = Vector3.zero;
                    }
                    else
                    {
                        ps.transform.localPosition = properties._offset;
                    }
                }
                else
                {
                    ps.transform.SetParent(null);
                    ps.transform.position = parent.TransformPoint(properties._offset);
                }

                if (properties._lockXOffset || properties._lockYOffset != HeightLock.Unlocked || properties._lockZOffset)
                {
                    AttachTransform.LockPosition(ps.gameObject, properties._lockXOffset, properties._lockYOffset, properties._lockZOffset);
                }

                if (properties._worldSpace)
                {
                    ps.transform.eulerAngles = properties._angles;

                    if (flipped)
                    {
                        // rotate this by 180
                        ps.transform.RotateAround(ps.transform.position, Vector3.up, 180.0f);
                    }
                }
                else
                {
                    if (properties._parent)
                    {
                        ps.transform.localEulerAngles = properties._angles; //感觉不好 没看明白 因为我们现在的粒子不挂角色身上
                    }
                    else
                    {
                        ps.transform.eulerAngles = parent.TransformDirection(properties._angles);//解决无父节点的旋转问题
                    }
                }

                // mirror the effect, for parented effects, this is done inside the attach transform
                if (flipped && !properties._parent)
                {
                    FlipWorldRotationByXYPlane(ps.transform);
                }

                ps.transform.localScale = properties._scale;
            }

            return(ps);
        }
Exemplo n.º 13
0
 public void SetAttachTransform(AttachTransform attachTransform)
 {
     _AttachTransform = attachTransform;
     _AttachTransform.UpdateManually = true;
 }