Exemplo n.º 1
0
        public Camera getCamera(AMITarget itarget)
        {
            if (itarget.isMeta)
            {
                if (!string.IsNullOrEmpty(_cameraPath))
                {
                    Transform t = itarget.GetCache(_cameraPath);
                    if (t)
                    {
                        return(t.GetComponent <Camera>());
                    }
                    else
                    {
                        t = AMUtil.GetTarget(itarget.root, _cameraPath);
                        itarget.SetCache(_cameraPath, t);
                        if (t)
                        {
                            return(t.GetComponent <Camera>());
                        }
                    }
                }

                return(null);
            }
            else
            {
                return(_camera);
            }
        }
Exemplo n.º 2
0
        public override List <GameObject> updateDependencies(AMITarget target, List <GameObject> newReferences, List <GameObject> oldReferences)
        {
            GameObject        go           = GetTarget(target) as GameObject;
            List <GameObject> lsFlagToKeep = new List <GameObject>();

            if (!go)
            {
                return(lsFlagToKeep);
            }
            for (int i = 0; i < oldReferences.Count; i++)
            {
                if (oldReferences[i] == go)
                {
                    Component _component = newReferences[i].GetComponent("Renderer");

                    // missing component
                    if (!_component)
                    {
                        Debug.LogWarning("Animator: Material Track component 'Renderer' not found on new reference for GameObject '" + go.name + "'. Duplicate not replaced.");
                        lsFlagToKeep.Add(oldReferences[i]);
                        return(lsFlagToKeep);
                    }
                    // missing property

                    SetTarget(target, newReferences[i].transform);
                    break;
                }
            }
            return(lsFlagToKeep);
        }
Exemplo n.º 3
0
        public override List <GameObject> updateDependencies(AMITarget target, List <GameObject> newReferences, List <GameObject> oldReferences)
        {
            AudioSource       src          = GetTarget(target) as AudioSource;
            List <GameObject> lsFlagToKeep = new List <GameObject>();

            if (!src)
            {
                return(lsFlagToKeep);
            }
            for (int i = 0; i < oldReferences.Count; i++)
            {
                if (oldReferences[i] == src.gameObject)
                {
                    AudioSource _audioSource = (AudioSource)newReferences[i].GetComponent(typeof(AudioSource));
                    // missing audiosource
                    if (!_audioSource)
                    {
                        Debug.LogWarning("Animator: Audio Track component 'AudioSource' not found on new reference for GameObject '" + src.gameObject.name + "'. Duplicate not replaced.");
                        lsFlagToKeep.Add(oldReferences[i]);
                        return(lsFlagToKeep);
                    }
                    SetTarget(target, newReferences[i].transform);
                    break;
                }
            }
            return(lsFlagToKeep);
        }
Exemplo n.º 4
0
        public bool setCamera(AMITarget itarget, Camera camera)
        {
            if (getCamera(itarget) != camera)
            {
                if (camera)
                {
                    if (itarget.isMeta)
                    {
                        _camera     = null;
                        _cameraPath = AMUtil.GetPath(itarget.root, camera);
                        itarget.SetCache(_cameraPath, camera.transform);
                    }
                    else
                    {
                        _camera     = camera;
                        _cameraPath = "";
                    }
                }
                else
                {
                    _camera     = null;
                    _cameraPath = "";
                }

                return(true);
            }
            return(false);
        }
Exemplo n.º 5
0
        public override void updateCache(AMITarget target)
        {
            base.updateCache(target);

            for (int i = 0; i < keys.Count; i++)
            {
                AMMaterialKey key = keys[i] as AMMaterialKey;

                if (key.version > 0 && key.version != version)
                {
                    //TODO: ...
                }

                key.version = version;

                if (keys.Count > (i + 1))
                {
                    key.endFrame = keys[i + 1].frame;
                }
                else
                {
                    if (!canTween || (i > 0 && !keys[i - 1].canTween))
                    {
                        key.interp = (int)AMKey.Interpolation.None;
                    }

                    key.endFrame = -1;
                }
            }
        }
Exemplo n.º 6
0
 public override List<GameObject> getDependencies(AMITarget itarget)
 {
     Transform t = GetTarget(itarget) as Transform;
     List<GameObject> ls = new List<GameObject>();
     if(t) ls.Add(t.gameObject);
     return ls;
 }
Exemplo n.º 7
0
 public override List<GameObject> getDependencies(AMITarget target)
 {
     GameObject go = GetTarget(target) as GameObject;
     List<GameObject> ls = new List<GameObject>();
     if(go) ls.Add(go);
     return ls;
 }
Exemplo n.º 8
0
 public void Pause(AMITarget itarget)
 {
     foreach (AMTrack track in trackValues)
     {
         track.Pause(itarget);
     }
 }
Exemplo n.º 9
0
 public void Resume(AMITarget itarget)
 {
     foreach (AMTrack track in trackValues)
     {
         track.Resume(itarget);
     }
 }
Exemplo n.º 10
0
 public void PlayComplete(AMITarget itarget)
 {
     foreach (AMTrack track in trackValues)
     {
         track.PlayComplete(itarget);
     }
 }
Exemplo n.º 11
0
 public void Stop(AMITarget itarget)
 {
     foreach (AMTrack track in trackValues)
     {
         track.Stop(itarget);
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Call this when we are switching take
 /// </summary>
 public void PlaySwitch(AMITarget itarget)
 {
     foreach (AMTrack track in trackValues)
     {
         track.PlaySwitch(itarget);
     }
 }
Exemplo n.º 13
0
 public void Reset(AMITarget itarget)
 {
     foreach (AMTrack track in trackValues) //call to start
     {
         track.Reset(itarget, frameRate);
     }
 }
Exemplo n.º 14
0
        // preview a frame
        public void previewFrame(AMITarget itarget, float _frame, bool orientationOnly = false, bool renderStill = true, bool play = false, float playSpeed = 1.0f)
        {
            // render camera switcher still texture if necessary
            if (renderStill)
            {
                renderCameraSwitcherStill(itarget, _frame);
            }

            if (orientationOnly)
            {
                foreach (AMTrack track in trackValues)
                {
                    if (track is AMOrientationTrack)   // || track is AMRotationTrack)
                    {
                        track.previewFrame(itarget, _frame, frameRate, play, playSpeed);
                    }
                }
            }
            else
            {
                foreach (AMTrack track in trackValues)
                {
                    track.previewFrame(itarget, _frame, frameRate, play, playSpeed);
                }
            }
        }
Exemplo n.º 15
0
        // add a new key
        public void addKey(AMITarget itarget, OnAddKey addCall, int _frame, Vector3 _position, int _interp, int _easeType)
        {
            foreach (AMTranslationKey key in keys)
            {
                // if key exists on frame, update key
                if (key.frame == _frame)
                {
                    key.position = _position;
                    key.interp   = _interp;
                    key.easeType = _easeType;
                    // update cache
                    updateCache(itarget);
                    return;
                }
            }
            AMTranslationKey a = addCall(gameObject, typeof(AMTranslationKey)) as AMTranslationKey;

            a.frame    = _frame;
            a.position = _position;
            a.interp   = _interp;
            a.easeType = _easeType;

            // add a new key
            keys.Add(a);
            // update cache
            updateCache(itarget);
        }
Exemplo n.º 16
0
 public void SetAnimScale(AMITarget itarget, float scale)
 {
     foreach (AMTrack track in trackValues)
     {
         track.SetAnimScale(itarget, scale);
     }
 }
Exemplo n.º 17
0
        // preview a frame in the scene view
        public override void previewFrame(AMITarget target, float frame, int frameRate, bool play, float playSpeed)
        {
            GameObject go = GetTarget(target) as GameObject;

            if(keys == null || keys.Count <= 0) {
                return;
            }
            if(!go) return;

            // if before the first frame
            if(frame < (float)keys[0].frame) {
                //go.rotation = (cache[0] as AMPropertyAction).getStartQuaternion();
                go.SetActive(startActive);
                return;
            }
            // if beyond or equal to last frame
            if(frame >= (float)(keys[keys.Count - 1] as AMGOSetActiveKey).frame) {
                go.SetActive((keys[keys.Count - 1] as AMGOSetActiveKey).setActive);
                return;
            }
            // if lies on property action
            foreach(AMGOSetActiveKey key in keys) {
                if((frame < (float)key.frame) || (key.endFrame != -1 && frame >= (float)key.endFrame)) continue;

                go.SetActive(key.setActive);
                return;
            }
        }
Exemplo n.º 18
0
        public override void updateCache(AMITarget target)
        {
            base.updateCache(target);

            // save rotation
            //Quaternion temp = obj.rotation;

            for (int i = 0; i < keys.Count; i++)
            {
                AMOrientationKey key = keys[i] as AMOrientationKey;

                key.version = version;

                if (keys.Count > (i + 1))
                {
                    key.endFrame = keys[i + 1].frame;
                }
                else
                {
                    if (i > 0 && !keys[i - 1].canTween)
                    {
                        key.interp = (int)AMKey.Interpolation.None;
                    }

                    key.endFrame = -1;
                }
            }
            // restore rotation
            //if(restoreRotation) obj.rotation = temp;
        }
Exemplo n.º 19
0
        // returns true if autoKey successful, sets output key
        public bool autoKey(AMITarget itarget, OnAddKey addCall, Transform aObj, int frame, int frameRate)
        {
            Transform t = GetTarget(itarget) as Transform;

            if (!t || t != aObj)
            {
                return(false);
            }
            Quaternion r = t.localRotation;

            if (keys.Count <= 0)
            {
                if (r != cachedInitialRotation)
                {
                    // if updated position, addkey
                    addKey(itarget, addCall, frame, r);
                    return(true);
                }

                return(false);
            }
            Quaternion oldRot = getRotationAtFrame(frame, frameRate);

            if (r != oldRot)
            {
                // if updated position, addkey
                addKey(itarget, addCall, frame, r);
                return(true);
            }

            return(false);
        }
Exemplo n.º 20
0
        public AMKey[] removeSelectedKeysFromTrack(AMTakeData take, AMITarget itarget, int track_id)
        {
            List <AMKey> dkeys = new List <AMKey>();

            bool    didDeleteKeys = false;
            AMTrack track         = take.getTrack(track_id);

            for (int i = 0; i < track.keys.Count; i++)
            {
                if (!isFrameInContextSelection(track.keys[i].frame))
                {
                    continue;
                }
                dkeys.Add(track.keys[i]);
                track.keys.Remove(track.keys[i]);
                i--;
                didDeleteKeys = true;
            }
            if (didDeleteKeys)
            {
                track.updateCache(itarget);
            }

            return(dkeys.ToArray());
        }
Exemplo n.º 21
0
 public override List<GameObject> getDependencies(AMITarget target)
 {
     AudioSource src = GetTarget(target) as AudioSource;
     List<GameObject> ls = new List<GameObject>();
     if(src) ls.Add(src.gameObject);
     return ls;
 }
Exemplo n.º 22
0
        public override void maintainKey(AMITarget itarget, UnityEngine.Object targetObj)
        {
            if (itarget.isMeta)
            {
                if (string.IsNullOrEmpty(targetPath))
                {
                    if (target)
                    {
                        targetPath = AMUtil.GetPath(itarget.root, target);
                        itarget.SetCache(targetPath, target);
                    }
                }

                target = null;
            }
            else
            {
                if (!target)
                {
                    if (!string.IsNullOrEmpty(targetPath))
                    {
                        target = itarget.GetCache(targetPath);
                        if (!target)
                        {
                            target = AMUtil.GetTarget(itarget.root, targetPath);
                        }
                    }
                }

                targetPath = "";
            }
        }
Exemplo n.º 23
0
            //private float[] mFadeParams;

            public void Apply(AMCameraSwitcherKey camSwitcher, int frameRate, AMITarget itarget, Camera[] allCameras, bool backwards)
            {
                if (mCamSwitcher != camSwitcher)
                {
                    mCamSwitcher = camSwitcher;

                    float[] fadeParams = mCamSwitcher.cameraFadeParameters.ToArray();
                    mIsReversed = AMUtil.isTransitionReversed(mCamSwitcher.type, fadeParams);
                    mCam        = mCamSwitcher.getCamera(itarget);
                    mCamEnd     = mCamSwitcher.getCameraEnd(itarget);
                    mAllCams    = allCameras;

                    if (mCamSwitcher.cameraFadeType == (int)Fade.None)
                    {
                        mCamSwitcher.CameraFadeNoneTargets(mCamSwitcher.typeEnd, mCamSwitcher.colorEnd, mCamEnd, mAllCams);
                        mCamSwitcher.CameraEnd(mIsReversed, mCam, mCamEnd, mAllCams);
                    }
                    else
                    {
                        mCamSwitcher.CameraGenerateFadeTargets(mIsReversed, mCam, mCamEnd, mAllCams, fadeParams);
                    }
                }

                mBackwards = backwards;
            }
Exemplo n.º 24
0
        public cfTuple getCameraFadeTupleForFrame(AMITarget itarget, int frame)
        {
            if (keys == null || keys.Count <= 0)
            {
                return(new cfTuple(0, 0, 0, null, null, false));
            }
            for (int i = 0; i < keys.Count; i++)
            {
                AMCameraSwitcherKey key = keys[i] as AMCameraSwitcherKey;
                // compact
                if (frame < key.frame)
                {
                    break;
                }
                else if (frame < key.endFrame)
                {
                    if (!key.still || key.cameraFadeType == (int)AMCameraSwitcherKey.Fade.None || key.targetsAreEqual(itarget))
                    {
                        break;
                    }
                    bool isReversed = key.isReversed();

                    if (isReversed)
                    {
                        return(new cfTuple(key.endFrame, key.typeEnd, key.type, key.getCameraEnd(itarget), key.getCamera(itarget), isReversed));
                    }
                    else
                    {
                        return(new cfTuple(key.frame, key.type, key.typeEnd, key.getCamera(itarget), key.getCameraEnd(itarget), isReversed));
                    }
                    //return new cfTuple((isReversed ? (cache[i] as AMCameraSwitcherAction).endFrame : (cache[i] as AMCameraSwitcherAction).startFrame),(cache[i] as AMCameraSwitcherAction).startCamera,(cache[i] as AMCameraSwitcherAction).endCamera,isReversed);
                }
            }
            return(new cfTuple(0, 0, 0, null, null, false));
        }
Exemplo n.º 25
0
        public override void PlayStart(AMITarget itarget, float frame, int frameRate, float animScale)
        {
            //swap to material instance
            mMatCtrl.Apply(_matInd, GetMaterial(itarget));

            base.PlayStart(itarget, frame, frameRate, animScale);
        }
Exemplo n.º 26
0
        public override List <GameObject> updateDependencies(AMITarget itarget, List <GameObject> newReferences, List <GameObject> oldReferences)
        {
            List <GameObject> lsFlagToKeep = new List <GameObject>();

            for (int i = 0; i < oldReferences.Count; i++)
            {
                foreach (AMCameraSwitcherKey key in keys)
                {
                    Camera keyCamera = key.GetComponent <Camera>();
                    if (key.type == 0 && keyCamera && oldReferences[i] == keyCamera.gameObject)
                    {
                        Camera _camera = (Camera)newReferences[i].GetComponent(typeof(Camera));
                        // missing camera
                        if (!_camera)
                        {
                            Debug.LogWarning("Animator: Camera Switcher component 'Camera' not found on new reference for GameObject '" + keyCamera.name + "'. Duplicate not replaced.");
                            lsFlagToKeep.Add(oldReferences[i]);
                            continue;
                        }
                        key.setCamera(itarget, _camera);
                    }
                }
            }

            return(lsFlagToKeep);
        }
Exemplo n.º 27
0
        void Init(AMITarget target)
        {
            Renderer r = GetTarget(target) as Renderer;

            if (r)
            {
                Material mat = GetMaterial(r);
                if (mat)
                {
                    mMatCtrl = r.GetComponent <MaterialController>();
                    if (!mMatCtrl)
                    {
                        mMatCtrl = r.gameObject.AddComponent <MaterialController>();
                    }
                    mMatInstance = mMatCtrl.Instance(_matInd, mat);
                }
                else
                {
                    Debug.LogWarning("Material not found for track: " + name);
                }
            }
            else
            {
                Debug.LogWarning("Renderer not found for track: " + name);
            }

            mPropId = Shader.PropertyToID(_property);

            mIsInit = true;
        }
Exemplo n.º 28
0
        public override void updateCache(AMITarget itarget)
        {
            base.updateCache(itarget);

            for (int i = 0; i < keys.Count; i++)
            {
                AMCameraSwitcherKey key = keys[i] as AMCameraSwitcherKey;

                key.version = version;

                if (keys.Count > i + 1)
                {
                    AMCameraSwitcherKey nextKey = keys[i + 1] as AMCameraSwitcherKey;
                    key.endFrame = nextKey.frame;
                    key.typeEnd  = nextKey.type;
                    if (key.typeEnd == 0)
                    {
                        key.setCameraEnd(nextKey);
                    }
                    else
                    {
                        key.colorEnd = nextKey.color;
                    }
                }
                else
                {
                    key.endFrame = -1;
                }
            }

            _cachedAllCameras = getAllCameras(itarget);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Gets the target relative to animator's hierarchy if we are referencing via AnimatorMeta
        /// </summary>
        public UnityEngine.Object GetTarget(AMITarget target)
        {
            UnityEngine.Object ret = null;

            if (target != null && target.isMeta)
            {
                Transform tgt = target.GetCache(_targetPath);
                if (tgt)
                {
                    ret = GetSerializeObject(tgt.gameObject);
                }
                else
                {
                    tgt = Utility.GetTarget(target.root, _targetPath);
                    target.SetCache(_targetPath, tgt);
                    if (tgt)
                    {
                        ret = GetSerializeObject(tgt.gameObject);
                    }
                }
            }
            else
            {
                ret = GetSerializeObject(null);
            }

            return(ret);
        }
Exemplo n.º 30
0
 // add a new key
 public void addKey(AMITarget itarget, OnAddKey addCall, int _frame, Camera camera = null,/*int? type = null, Camera camera = null, Color? color = null,*/ AMCameraSwitcherKey keyToClone = null)
 {
     foreach(AMCameraSwitcherKey key in keys) {
         // if key exists on frame, update key
         if(key.frame == _frame) {
             if(camera != null) {
                 key.setCamera(itarget, camera);
                 key.type = 0;
                 updateCache(itarget);
             }
             return;
         }
     }
     AMCameraSwitcherKey a = addCall(gameObject, typeof(AMCameraSwitcherKey)) as AMCameraSwitcherKey;
     if(keyToClone) {
         keyToClone.CopyTo(a);
     }
     else {
         a.type = 0;
         a.still = !AMTakeData.isProLicense;
         a.easeType = (int)EaseType.EaseOutSine;
     }
     a.frame = _frame;
     if(camera != null) {
         a.setCamera(itarget, camera);
         a.type = 0;
     }
     // add a new key
     keys.Add(a);
     // update cache
     updateCache(itarget);
 }
Exemplo n.º 31
0
        // returns true if autoKey successful
        public bool autoKey(AMITarget itarget, OnAddKey addCall, Transform aobj, int frame, int frameRate)
        {
            Transform t = GetTarget(itarget) as Transform;

            if (!t || aobj != t)
            {
                return(false);
            }

            if (keys.Count <= 0)
            {
                if (GetPosition(t) != cachedInitialPosition)
                {
                    // if updated position, addkey
                    addKey(itarget, addCall, frame, GetPosition(t));
                    return(true);
                }
                return(false);
            }

            Vector3 oldPos = getPositionAtFrame(t, frame, frameRate, false);

            if (GetPosition(t) != oldPos)
            {
                // if updated position, addkey
                addKey(itarget, addCall, frame, GetPosition(t));
                return(true);
            }

            return(false);
        }
Exemplo n.º 32
0
        // update cache (optimized)
        public override void updateCache(AMITarget target)
        {
            base.updateCache(target);

            for (int i = 0; i < keys.Count; i++)
            {
                AMRotationKey key = keys[i] as AMRotationKey;

                key.version = version;

                //a.type = (keys[i] as AMRotationKey).type;

                if (keys.Count > (i + 1))
                {
                    key.endFrame = keys[i + 1].frame;
                }
                else
                {
                    if (i > 0 && !keys[i - 1].canTween)
                    {
                        key.interp = (int)AMKey.Interpolation.None;
                    }

                    key.endFrame = -1;
                }
            }
        }
Exemplo n.º 33
0
        // preview a frame in the scene view
        public override void previewFrame(AMITarget target, float frame, int frameRate, bool play, float playSpeed)
        {
            Transform t = GetTarget(target) as Transform;

            if (!t)
            {
                return;
            }
            if (keys == null || keys.Count <= 0)
            {
                return;
            }

            // if before or equal to first frame, or is the only frame
            AMRotationEulerKey firstKey = keys[0] as AMRotationEulerKey;

            if (firstKey.endFrame == -1 || (frame <= (float)firstKey.frame && !firstKey.canTween))
            {
                ApplyRot(t, firstKey.rotation);
                return;
            }

            // if lies on rotation action
            for (int i = 0; i < keys.Count; i++)
            {
                AMRotationEulerKey key     = keys[i] as AMRotationEulerKey;
                AMRotationEulerKey keyNext = i + 1 < keys.Count ? keys[i + 1] as AMRotationEulerKey : null;

                if (frame >= (float)key.endFrame && keyNext != null && (!keyNext.canTween || keyNext.endFrame != -1))
                {
                    continue;
                }
                // if no ease
                if (!key.canTween || keyNext == null)
                {
                    ApplyRot(t, key.rotation);
                    return;
                }
                // else easing function

                float numFrames = (float)key.getNumberOfFrames(frameRate);

                float framePositionInAction = Mathf.Clamp(frame - (float)key.frame, 0f, numFrames);

                Vector3 qStart = key.rotation;
                Vector3 qEnd   = keyNext.rotation;

                if (key.hasCustomEase())
                {
                    ApplyRot(t, Vector3.Lerp(qStart, qEnd, Utility.EaseCustom(0.0f, 1.0f, framePositionInAction / numFrames, key.easeCurve)));
                }
                else
                {
                    var ease = Utility.GetEasingFunction((Ease)key.easeType);
                    ApplyRot(t, Vector3.Lerp(qStart, qEnd, ease(framePositionInAction, numFrames, key.amplitude, key.period)));
                }

                return;
            }
        }
Exemplo n.º 34
0
        // add a new key
        public void addKey(AMITarget target, OnAddKey addCall, int _frame, Quaternion _rotation)
        {
            foreach (AMRotationKey key in keys)
            {
                // if key exists on frame, update key
                if (key.frame == _frame)
                {
                    key.rotation = _rotation;
                    // update cache
                    updateCache(target);
                    return;
                }
            }
            AMRotationKey a = addCall(gameObject, typeof(AMRotationKey)) as AMRotationKey;

            a.frame    = _frame;
            a.rotation = _rotation;
            // set default ease type to linear
            a.easeType = (int)Ease.Linear;

            // add a new key
            keys.Add(a);
            // update cache
            updateCache(target);
        }
Exemplo n.º 35
0
        public override List<GameObject> updateDependencies(AMITarget target, List<GameObject> newReferences, List<GameObject> oldReferences)
        {
            GameObject go = GetTarget(target) as GameObject;
            bool didUpdateObj = false;
            bool didUpdateParameter = false;
            if(go) {
                for(int i = 0; i < oldReferences.Count; i++) {
                    if(oldReferences[i] == go) {
                        // check if new GameObject has all the required components
                        foreach(AMEventKey key in keys) {
                            string componentName = key.getComponentName();
                            if(newReferences[i].GetComponent(componentName) == null) {
                                // missing component
                                Debug.LogWarning("Animator: Event Track component '" + componentName + "' not found on new reference for GameObject '" + obj.name + "'. Duplicate not replaced.");
                                List<GameObject> lsFlagToKeep = new List<GameObject>();
                                lsFlagToKeep.Add(oldReferences[i]);
                                return lsFlagToKeep;
                            }
                        }
                        SetTarget(target, newReferences[i].transform);
                        didUpdateObj = true;
                        break;
                    }

                }
            }
            foreach(AMEventKey key in keys) {
                if(key.updateDependencies(newReferences, oldReferences, didUpdateObj, go) && !didUpdateParameter) didUpdateParameter = true;
            }

            if(didUpdateObj || didUpdateParameter) updateCache(target);

            return new List<GameObject>();
        }
Exemplo n.º 36
0
        public override void maintainTrack(AMITarget itarget)
        {
            base.maintainTrack(itarget);

            if (string.IsNullOrEmpty(componentName))
            {
                if (component)
                {
                    componentName = component.GetType().Name;
                }
            }

            if (itarget.isMeta)
            {
                component = null;
            }
            else if (!component && !string.IsNullOrEmpty(componentName))
            {
                GameObject go = GetTarget(itarget) as GameObject;
                if (go)
                {
                    component = go.GetComponent(componentName);
                }
            }
        }
Exemplo n.º 37
0
    public AMSequence(AMITarget itarget, int id, AMTakeData take)
    {
        mTarget = itarget;
        mId = id;
        mTake = take;

        if(mTake.loopBackToFrame > 0 && mTake.numLoop <= 0)
            mTake.numLoop = 1;
    }
Exemplo n.º 38
0
 public override List<GameObject> getDependencies(AMITarget target)
 {
     GameObject go = GetTarget(target) as GameObject;
     List<GameObject> ls = new List<GameObject>();
     if(go) ls.Add(go);
     foreach(AMEventKey key in keys) {
         ls = ls.Union(key.getDependencies()).ToList();
     }
     return ls;
 }
Exemplo n.º 39
0
 public override void Pause(AMITarget itarget)
 {
     AudioSource src = GetTarget(itarget) as AudioSource;
     if(src && src.isPlaying) {
         pausedLoop = src.loop && src.clip && src.clip.length - src.time < 1f; //only end loop if it's short enough to do so
         if(pausedLoop)
             src.loop = false;
         else
             src.Pause();
         paused = true;
     }
 }
Exemplo n.º 40
0
 public Camera[] getAllCameras(AMITarget itarget)
 {
     List<Camera> lsCameras = new List<Camera>();
     foreach(AMCameraSwitcherKey key in keys) {
         Camera cam = key.getCamera(itarget);
         if(key.type == 0 && cam) {
             if(lsCameras.IndexOf(cam) == -1) {
                 lsCameras.Add(cam);
             }
         }
     }
     return lsCameras.ToArray();
 }
Exemplo n.º 41
0
        // draw gizmos
        public override void drawGizmos(AMITarget itarget, float gizmo_size, bool inPlayMode, int frame)
        {
            if(!obj) return;

            // draw line to target
            bool isLineDrawn = false;
            if(!inPlayMode) {
                for(int i = 0; i < keys.Count; i++) {
                    AMOrientationKey key = keys[i] as AMOrientationKey;
                    if(key == null)
                        continue;

                    AMOrientationKey keyNext = i + 1 < keys.Count ? keys[i + 1] as AMOrientationKey : null;

                    Transform t = key.GetTarget(itarget);
                    if(t) {
                        //draw target
                        Gizmos.color = new Color(245f/255f, 107f/255f, 30f/255f, 1f);
                        Gizmos.DrawSphere(t.position, 0.2f * (AnimatorTimeline.e_gizmoSize/0.1f));

                        //draw line
                        if(!isLineDrawn) {
                            if(key.frame > frame) isLineDrawn = true;
                            if(frame >= key.frame && frame <= key.endFrame) {
                                if(!keyNext || t == keyNext.GetTarget(itarget)) {
                                    Gizmos.color = new Color(245f / 255f, 107f / 255f, 30f / 255f, 0.2f);
                                    Gizmos.DrawLine(obj.transform.position, t.position);
                                }
                                isLineDrawn = true;
                            }
                        }
                    }
                }
            }
            // draw arrow
            Gizmos.color = new Color(245f / 255f, 107f / 255f, 30f / 255f, 1f);
            Vector3 pos = obj.transform.position;
            float size = (1.2f * (gizmo_size / 0.1f));
            if(size < 0.1f) size = 0.1f;
            Vector3 direction = obj.forward * size;
            float arrowHeadAngle = 20f;
            float arrowHeadLength = 0.3f * size;

            Gizmos.DrawRay(pos, direction);

            Vector3 right = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 + arrowHeadAngle, 0) * new Vector3(0, 0, 1);
            Vector3 left = Quaternion.LookRotation(direction) * Quaternion.Euler(0, 180 - arrowHeadAngle, 0) * new Vector3(0, 0, 1);
            Gizmos.DrawRay(pos + direction, right * arrowHeadLength);
            Gizmos.DrawRay(pos + direction, left * arrowHeadLength);
        }
Exemplo n.º 42
0
 // add a new key
 public void addKey(AMITarget itarget, OnAddKey addCall, int _frame)
 {
     foreach(AMEventKey key in keys) {
         // if key exists on frame, do nothing
         if(key.frame == _frame) {
             return;
         }
     }
     AMEventKey a = addCall(gameObject, typeof(AMEventKey)) as AMEventKey;
     a.frame = _frame;
     // add a new key
     keys.Add(a);
     // update cache
     updateCache(itarget);
 }
Exemplo n.º 43
0
 // add a new key
 public void addKey(AMITarget target, OnAddKey addCall, int _frame)
 {
     foreach(AMGOSetActiveKey key in keys) {
         // if key exists on frame, update
         if(key.frame == _frame) {
             key.setActive = true;
             updateCache(target);
             return;
         }
     }
     AMGOSetActiveKey a = addCall(gameObject, typeof(AMGOSetActiveKey)) as AMGOSetActiveKey;
     a.frame = _frame;
     a.setActive = true;
     // add a new key
     keys.Add(a);
     // update cache
     updateCache(target);
 }
Exemplo n.º 44
0
 // add a new key
 public void addKey(AMITarget itarget, OnAddKey addCall, int _frame, AudioClip _clip, bool _loop)
 {
     foreach(AMAudioKey key in keys) {
         // if key exists on frame, update key
         if(key.frame == _frame) {
             key.audioClip = _clip;
             key.loop = _loop;
             // update cache
             updateCache(itarget);
         }
     }
     AMAudioKey a = addCall(gameObject, typeof(AMAudioKey)) as AMAudioKey;
     a.frame = _frame;
     a.audioClip = _clip;
     a.loop = _loop;
     // add a new key
     keys.Add(a);
     // update cache
     updateCache(itarget);
 }
Exemplo n.º 45
0
    public Camera getCamera(AMITarget itarget)
    {
        if(itarget.isMeta) {
            if(!string.IsNullOrEmpty(_cameraPath)) {
                Transform t = itarget.GetCache(_cameraPath);
                if(t)
                    return t.GetComponent<Camera>();
                else {
                    t = AMUtil.GetTarget(itarget.root, _cameraPath);
                    itarget.SetCache(_cameraPath, t);
                    if(t)
                        return t.GetComponent<Camera>();
                }
            }

            return null;
        }
        else
            return _camera;
    }
Exemplo n.º 46
0
        // add a new key, default interpolation and easeType
        public void addKey(AMITarget itarget, OnAddKey addCall, int _frame, Vector3 _position)
        {
            foreach(AMTranslationKey key in keys) {
                // if key exists on frame, update key
                if(key.frame == _frame) {
                    key.position = _position;
                    // update cache
                    updateCache(itarget);
                    return;
                }
            }
            AMTranslationKey a = addCall(gameObject, typeof(AMTranslationKey)) as AMTranslationKey;
            a.frame = _frame;
            a.position = _position;

            // add a new key
            keys.Add(a);
            // update cache
            updateCache(itarget);
        }
Exemplo n.º 47
0
 // add a new key
 public void addKey(AMITarget itarget, OnAddKey addCall, int _frame, Transform target)
 {
     foreach(AMOrientationKey key in keys) {
         // if key exists on frame, update key
         if(key.frame == _frame) {
             key.SetTarget(itarget, target);
             // update cache
             updateCache(itarget);
             return;
         }
     }
     AMOrientationKey a = addCall(gameObject, typeof(AMOrientationKey)) as AMOrientationKey;
     a.frame = _frame;
     a.SetTarget(itarget, target);
     // set default ease type to linear
     a.easeType = (int)0;// AMTween.EaseType.linear;
     // add a new key
     keys.Add(a);
     // update cache
     updateCache(itarget);
 }
Exemplo n.º 48
0
 // add a new key
 public void addKey(AMITarget itarget, OnAddKey addCall, int _frame, AnimationClip _clip, WrapMode _wrapMode)
 {
     foreach(AMAnimationKey key in keys) {
         // if key exists on frame, update key
         if(key.frame == _frame) {
             key.amClip = _clip;
             key.wrapMode = _wrapMode;
             // update cache
             updateCache(itarget);
             return;
         }
     }
     AMAnimationKey a = addCall(gameObject, typeof(AMAnimationKey)) as AMAnimationKey;
     a.frame = _frame;
     a.amClip = _clip;
     a.wrapMode = _wrapMode;
     // add a new key
     keys.Add(a);
     // update cache
     updateCache(itarget);
 }
Exemplo n.º 49
0
    public cfTuple getCameraFadeTupleForFrame(AMITarget itarget, int frame)
    {
        if(keys == null || keys.Count <= 0) {
            return new cfTuple(0, 0, 0, null, null, false);
        }
        for(int i=0; i<keys.Count; i++) {
            AMCameraSwitcherKey key = keys[i] as AMCameraSwitcherKey;
            // compact
            if(frame < key.frame) {
                break;
            }
            else if(frame < key.endFrame) {
                if(!key.still || key.cameraFadeType == (int)AMCameraSwitcherKey.Fade.None || key.targetsAreEqual(itarget)) break;
                bool isReversed = key.isReversed();

                if(isReversed) return new cfTuple(key.endFrame, key.typeEnd, key.type, key.getCameraEnd(itarget), key.getCamera(itarget), isReversed);
                else return new cfTuple(key.frame, key.type, key.typeEnd, key.getCamera(itarget), key.getCameraEnd(itarget), isReversed);
                //return new cfTuple((isReversed ? (cache[i] as AMCameraSwitcherAction).endFrame : (cache[i] as AMCameraSwitcherAction).startFrame),(cache[i] as AMCameraSwitcherAction).startCamera,(cache[i] as AMCameraSwitcherAction).endCamera,isReversed);
            }
        }
        return new cfTuple(0, 0, 0, null, null, false);
    }
Exemplo n.º 50
0
        // add a new key
        public void addKey(AMITarget target, OnAddKey addCall, int _frame, Quaternion _rotation)
        {
            foreach(AMRotationKey key in keys) {
                // if key exists on frame, update key
                if(key.frame == _frame) {
                    key.rotation = _rotation;
                    // update cache
                    updateCache(target);
                    return;
                }
            }
            AMRotationKey a = addCall(gameObject, typeof(AMRotationKey)) as AMRotationKey;
            a.frame = _frame;
            a.rotation = _rotation;
            // set default ease type to linear
            a.easeType = (int)EaseType.Linear;

            // add a new key
            keys.Add(a);
            // update cache
            updateCache(target);
        }
Exemplo n.º 51
0
        // preview a frame in the scene view
        public override void previewFrame(AMITarget target, float frame, int frameRate, bool play, float playSpeed)
        {
            GameObject go = GetTarget(target) as GameObject;
            if(!go || keys.Count == 0) return;

            Animation anim = go.GetComponent<Animation>();

            if(frame < keys[0].frame) {
                AMAnimationKey amKey = keys[0] as AMAnimationKey;
                if(amKey.amClip)
                    AMUtil.SampleAnimation(anim, amKey.amClip.name, amKey.wrapMode, amKey.crossfade ? 0.0f : 1.0f, 0.0f);
                return;
            }

            for(int i = keys.Count - 1; i >= 0; i--) {
                if(keys[i].frame <= frame) {
                    AMAnimationKey amKey = keys[i] as AMAnimationKey;
                    if(amKey.amClip) {
                        float t = (frame - (float)amKey.frame) / (float)frameRate;

                        if(amKey.crossfade) {
                            if(i > 0) {
                                AMAnimationKey amPrevKey = keys[i - 1] as AMAnimationKey;
                                if(amPrevKey.amClip) {
                                    float prevT = (frame - (float)amPrevKey.frame) / (float)frameRate;
                                    AMUtil.SampleAnimationCrossFade(anim, amKey.crossfadeTime, amPrevKey.amClip.name, amPrevKey.wrapMode, prevT, amKey.amClip.name, amKey.wrapMode, t);
                                }
                            }
                            else
                                AMUtil.SampleAnimationFadeIn(anim, amKey.amClip.name, amKey.wrapMode, amKey.crossfadeTime, t);
                        }
                        else
                            AMUtil.SampleAnimation(anim, amKey.amClip.name, amKey.wrapMode, 1.0f, t);
                    }
                    break;
                }
            }
        }
Exemplo n.º 52
0
        // returns true if autoKey successful, sets output key
        public bool autoKey(AMITarget itarget, OnAddKey addCall, Transform aObj, int frame, int frameRate)
        {
            Transform t = GetTarget(itarget) as Transform;
            if(!t || t != aObj) { return false; }
            Quaternion r = t.localRotation;
            if(keys.Count <= 0) {
                if(r != cachedInitialRotation) {
                    // if updated position, addkey
                    addKey(itarget, addCall, frame, r);
                    return true;
                }

                return false;
            }
            Quaternion oldRot = getRotationAtFrame(frame, frameRate);
            if(r != oldRot) {
                // if updated position, addkey
                addKey(itarget, addCall, frame, r);
                return true;
            }

            return false;
        }
Exemplo n.º 53
0
        public override void updateCache(AMITarget target)
        {
            base.updateCache(target);

            for(int i = 0; i < keys.Count; i++) {
                AMMaterialKey key = keys[i] as AMMaterialKey;

                if(key.version > 0 && key.version != version) {
                    //TODO: ...
                }

                key.version = version;

                if(keys.Count > (i + 1)) key.endFrame = keys[i + 1].frame;
                else {
                    if(!canTween || (i > 0 && !keys[i-1].canTween))
                        key.interp = (int)AMKey.Interpolation.None;

                    key.endFrame = -1;
                }
            }
        }
Exemplo n.º 54
0
 public override AnimatorTimeline.JSONInit getJSONInit(AMITarget target)
 {
     // no initial values to set
     return null;
 }
Exemplo n.º 55
0
        public override void PlayStart(AMITarget itarget, float frame, int frameRate, float animScale)
        {
            //swap to material instance
            mMatCtrl.Apply(_matInd, GetMaterial(itarget));

            base.PlayStart(itarget, frame, frameRate, animScale);
        }
Exemplo n.º 56
0
        public override List<GameObject> updateDependencies(AMITarget target, List<GameObject> newReferences, List<GameObject> oldReferences)
        {
            GameObject go = GetTarget(target) as GameObject;
            List<GameObject> lsFlagToKeep = new List<GameObject>();
            if(!go) return lsFlagToKeep;
            for(int i = 0; i < oldReferences.Count; i++) {
                if(oldReferences[i] == go) {
                    // missing animation
                    if(!newReferences[i].GetComponent(typeof(Animation))) {
                        Debug.LogWarning("Animator: Animation Track component 'Animation' not found on new reference for GameObject '" + go.name + "'. Duplicate not replaced.");
                        lsFlagToKeep.Add(oldReferences[i]);
                        return lsFlagToKeep;
                    }
                    SetTarget(target, newReferences[i].transform);
                    break;
                }
            }

            return lsFlagToKeep;
        }
Exemplo n.º 57
0
        void Init(AMITarget target)
        {
            Renderer r = GetTarget(target) as Renderer;
            if(r) {
                Material mat = GetMaterial(r);
                if(mat) {
                    mMatCtrl = r.GetComponent<AMMaterialController>();
                    if(!mMatCtrl) mMatCtrl = r.gameObject.AddComponent<AMMaterialController>();
                    mMatInstance = mMatCtrl.Instance(_matInd, mat);
                }
                else
                    Debug.LogWarning("Material not found for track: "+name);
            }
            else
                Debug.LogWarning("Renderer not found for track: "+name);

            mPropId = Shader.PropertyToID(_property);

            mIsInit = true;
        }
Exemplo n.º 58
0
        public override List<GameObject> updateDependencies(AMITarget target, List<GameObject> newReferences, List<GameObject> oldReferences)
        {
            GameObject go = GetTarget(target) as GameObject;
            List<GameObject> lsFlagToKeep = new List<GameObject>();
            if(!go) return lsFlagToKeep;
            for(int i = 0; i < oldReferences.Count; i++) {
                if(oldReferences[i] == go) {
                    Component _component = newReferences[i].GetComponent("Renderer");

                    // missing component
                    if(!_component) {
                        Debug.LogWarning("Animator: Material Track component 'Renderer' not found on new reference for GameObject '" + go.name + "'. Duplicate not replaced.");
                        lsFlagToKeep.Add(oldReferences[i]);
                        return lsFlagToKeep;
                    }
                    // missing property

                    SetTarget(target, newReferences[i].transform);
                    break;
                }
            }
            return lsFlagToKeep;
        }
Exemplo n.º 59
0
 public override void PlaySwitch(AMITarget itarget)
 {
     //revert material
     mMatCtrl.Revert(_matInd);
 }
Exemplo n.º 60
0
        public override void previewFrame(AMITarget target, float frame, int frameRate, bool play, float playSpeed)
        {
            if(keys == null || keys.Count <= 0) {
                return;
            }

            //TODO: figure out how to preview frame during edit
            if(Application.isPlaying) {
                if(!mIsInit)
                    Init(target);

                // if before or equal to first frame, or is the only frame
                AMMaterialKey ckey = keys[0] as AMMaterialKey;
                if((frame <= (float)ckey.frame) || ckey.endFrame == -1) {
                    ckey.ApplyValue(_propertyType, _property, mPropId, mMatInstance);
                    return;
                }
                // if not tweenable and beyond last frame
                ckey = keys[keys.Count - 1] as AMMaterialKey;
                if(!canTween && frame >= (float)ckey.frame) {
                    ckey.ApplyValue(_propertyType, _property, mPropId, mMatInstance);
                    return;
                }
                //if tweenable and beyond last tweenable
                ckey = keys[keys.Count - 2] as AMMaterialKey;
                if(frame >= (float)ckey.endFrame) {
                    ckey.ApplyValue(_propertyType, _property, mPropId, mMatInstance);
                    return;
                }
                // if lies on property action
                for(int i = 0; i < keys.Count; i++) {
                    AMMaterialKey key = keys[i] as AMMaterialKey;
                    AMMaterialKey keyNext = i + 1 < keys.Count ? keys[i + 1] as AMMaterialKey : null;

                    if((frame < (float)key.frame) || (frame > (float)key.endFrame)) continue;
                    //if(quickPreview && !key.targetsAreEqual()) return;	// quick preview; if action will execute then skip
                    // if on startFrame or is no tween
                    if(frame == (float)key.frame || ((!key.canTween || !canTween) && frame < (float)key.endFrame)) {
                        key.ApplyValue(_propertyType, _property, mPropId, mMatInstance);
                        return;
                    }
                    // if on endFrame
                    if(frame == (float)key.endFrame) {
                        if(!key.canTween || !canTween || !keyNext)
                            continue;
                        else {
                            keyNext.ApplyValue(_propertyType, _property, mPropId, mMatInstance);
                            return;
                        }
                    }
                    // else find value using easing function

                    float framePositionInAction = frame - (float)key.frame;
                    if(framePositionInAction < 0f) framePositionInAction = 0f;

                    float t;

                    if(key.hasCustomEase()) {
                        t = AMUtil.EaseCustom(0.0f, 1.0f, framePositionInAction / key.getNumberOfFrames(frameRate), key.easeCurve);
                    }
                    else {
                        TweenDelegate.EaseFunc ease = AMUtil.GetEasingFunction((EaseType)key.easeType);
                        t = ease(framePositionInAction, 0.0f, 1.0f, key.getNumberOfFrames(frameRate), key.amplitude, key.period);
                    }

                    AMMaterialKey.ApplyValueLerp(_propertyType, _property, mPropId, mMatInstance, key, keyNext, t);
                    return;
                }
            }
        }