Beispiel #1
0
        private static bool _IsAnimationWindowOpenAndWithClip(out object uawstate, out AnimationClip clip)
        {
            uawstate = null;
            clip     = null;

            EditorWindow uaw = (EditorWindow)EUtil.GetUnityAnimationWindow();

            if (uaw == null)
            {
                return(false);
            }
            uawstate = EUtil.GetUnityAnimationWindowState(uaw);
            if (uawstate == null)
            {
                return(false);
            }
            //clip = RCall.GetField("UnityEditorInternal.AnimationWindowState",
            //        "m_ActiveAnimationClip", uawstate) as AnimationClip;
            clip = RCall.GetProp("UnityEditorInternal.AnimationWindowState",
                                 "activeAnimationClip", uawstate) as AnimationClip;

            if (clip == null)
            {
                return(false);
            }

            return(true);
        }
    /// <summary>
    /// [HACK TRICK]
    /// get a TransformLst containing all active curves' transform in UAW
    /// </summary>
    private TrLst _GetActiveCurveTransforms()
    {
        //1. collect the TrPaths from active curves
        HashSet <string> strset = m_StrSet;

        strset.Clear();

        IList curves = (IList)RCall.GetProp("UnityEditorInternal.AnimationWindowState", "activeCurves", m_AnimationWindowState);

        for (int idx = 0; idx < curves.Count; ++idx)
        {
            object oneCurve = curves[idx]; //AnimationWindowCurve
            string onePath  = (string)RCall.GetProp("UnityEditorInternal.AnimationWindowCurve", "path", oneCurve);
            strset.Add(onePath);
        }

        //2. transform to Transform
        TrLst lst = new TrLst();

        for (var ie = strset.GetEnumerator(); ie.MoveNext();)
        {
            string    trPath = ie.Current;
            Transform tr     = m_ClipRoot.Find(trPath);
            if (tr != null)
            {
                lst.Add(tr);
            }
            else
            {
                Dbg.LogWarn("CCEditor._GetActiveCurveTransforms: cannot get transform for: {0}", trPath);
            }
        }

        return(lst);
    }
Beispiel #3
0
 public static object GetMainGameView()
 {
     System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
     System.Reflection.MethodInfo GetMainGameView = RCall.GetMethodInfo(T, "GetMainGameView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
     System.Object Res = GetMainGameView.Invoke(null, null);
     return(Res);
 }
    /// <summary>
    /// [HACK TRICK]
    /// use reflection to take out the data
    /// </summary>
    private bool _IsAnimEventPopupOpen()
    {
        Type t = RCall.GetTypeFromString("UnityEditor.AnimationEventPopup");

        UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(t);
        return(array.Length > 0);
    }
 private static PropertyInfo GetSystemCopyBufferProperty()
 {
     if (m_systemCopyBufferProperty == null)
     {
         Type T = typeof(GUIUtility);
         m_systemCopyBufferProperty = RCall.GetPropertyInfo(T, "systemCopyBuffer", BindingFlags.Static | BindingFlags.NonPublic);
         if (m_systemCopyBufferProperty == null)
         {
             throw new Exception("Can't access internal member 'GUIUtility.systemCopyBuffer' it may have been removed / renamed");
         }
     }
     return(m_systemCopyBufferProperty);
 }
        private static void _LoadPrefs()
        {
            m_IKConMarkerSize           = LoadPrefFloat(Pref_IKConMarkerSize, 0.6f);
            m_IKAngleConstraintArcColor = LoadPrefColor(Pref_IKConArcColor, new Color(0.2f, 0.2f, 0.8f, 0.4f));
            m_IKConeConstraintColor     = LoadPrefColor(Pref_IKConeConColor, new Color(0.2f, 0.2f, 0.8f, 1f));
            m_IKBoneLinkColor           = LoadPrefColor(Pref_IKBoneLinkColor, new Color32(255, 31, 173, 255));
            m_showInitInfos             = LoadPrefBool(Pref_ShowInitInfos, false);

            m_hasCAT        = (RCall.GetTypeFromString("MH.SMREditor", true) != null);
            m_hasIMMConsole = (RCall.GetTypeFromString("MH.MonoCSConsole", true) != null);

            m_isLoaded = true;
        }
Beispiel #7
0
    private static FieldInfo getFieldInfo(string goName, string componentName, string fieldName)
    {
        if (fieldName == null || componentName == null)
        {
            Debug.LogWarning("Animator: Error parsing FieldInfo or Component with null value");
            return(null);
        }
        string key = componentName + "." + fieldName;

        if (dictFieldInfos.ContainsKey(key))
        {
            return(dictFieldInfos[key]);
        }
        //dictFieldInfos.Add(key, Type.GetType(componentName).GetField(fieldName));
        dictFieldInfos.Add(key, RCall.GetFieldInfo(getCMP(goName, componentName).GetType(), fieldName));
        return(dictFieldInfos[key]);
    }
Beispiel #8
0
    private static PropertyInfo getPropertyInfo(string goName, string componentName, string propertyName)
    {
        if (propertyName == null || componentName == null)
        {
            Debug.LogWarning("Animator: Error parsing PropertyInfo or Component with null value");
            return(null);
        }
        string key = componentName + "." + propertyName;

        if (dictPropertyInfos.ContainsKey(key))
        {
            return(dictPropertyInfos[key]);
        }
        //Debug.Log(Type.GetType("UnityEngine.AudioSource"));
        //dictPropertyInfos.Add(key, Type.GetType(componentName).GetProperty(propertyName));
        dictPropertyInfos.Add(key, RCall.GetPropertyInfo(getCMP(goName, componentName).GetType(), propertyName));
        return(dictPropertyInfos[key]);
    }
Beispiel #9
0
        public static void FixRotation(Transform tr)
        {
#if UNITY_5_4_OR_NEWER
            //-------tr.SetLocalEulerHint(tr.GetLocalEulerAngles(_rotateOrder));------//
            Vector3 ea  = (Vector3)RCall.CallMtd("UnityEngine.Transform", "GetLocalEulerAngles", tr, 4);
            Vector3 rnd = UnityEngine.Random.onUnitSphere * 0.001f;
            Vector3 v   = ea + rnd;
            RCall.CallMtd("UnityEngine.Transform", "SetLocalEulerHint", tr, v);

            tr.localEulerAngles = v;

            //--------tr.SendTransformChangedScale();--------//
            if (tr.parent != null)
            {
                RCall.CallMtd("UnityEngine.Transform", "SendTransformChangedScale", tr);
            }
#endif
        }
Beispiel #10
0
    private static MethodInfo getMethodInfo(string goName, string componentName, string methodName, string[] typeNames)
    {
        if (methodName == null || componentName == null)
        {
            Debug.LogWarning("Animator: Error parsing MethodInfo or Component with null value");
            return(null);
        }
        string      key   = componentName + "." + methodName;
        List <Type> types = new List <Type>();

        if (typeNames != null)
        {
            for (int i = 0; i < typeNames.Length; i++)
            {
                key += "." + typeNames[i];
            }
            // setup type list
            foreach (string s in typeNames)
            {
                types.Add(Type.GetType(s));
            }
        }
        if (dictMethodInfos.ContainsKey(key))
        {
            return(dictMethodInfos[key]);
        }

        //dictMethodInfos.Add(key, Type.GetType(componentName).GetMethod(methodName,types.ToArray()));
        MethodInfo m;

        if (typeNames == null)
        {
            m = RCall.GetMethodInfo(getCMP(goName, componentName).GetType(), methodName);
        }
        else
        {
            m = RCall.GetMethodInfo(getCMP(goName, componentName).GetType(), methodName, types.ToArray());
        }
        dictMethodInfos.Add(key, m);
        //dictMethodInfos.Add(key, getCMP(goName,componentName).GetType().GetMethod(methodName,types.ToArray()));
        return(dictMethodInfos[key]);
    }
Beispiel #11
0
    /// <summary>
    /// [HACK TRICK]
    /// update every loop,
    /// current in-edit clip, clip's rootTr
    /// </summary>
    private void _UpdateInternalInfo()
    {
        AnimationClip curClip = null;
        Transform     rootTr  = null;

        m_AnimationWindowState = EUtil.GetUnityAnimationWindowState(m_UAW);
        if (m_AnimationWindowState != null)
        {
            curClip = RCall.GetField("UnityEditorInternal.AnimationWindowState",
                                     "m_ActiveAnimationClip", m_AnimationWindowState) as AnimationClip;

#if U5
            GameObject rootGO = RCall.GetProp("UnityEditorInternal.AnimationWindowState",
                                              "activeRootGameObject", m_AnimationWindowState) as GameObject;
#else
            GameObject rootGO = RCall.GetField("UnityEditorInternal.AnimationWindowState",
                                               "m_RootGameObject", m_AnimationWindowState) as GameObject;
#endif
            if (rootGO != null)
            {
                rootTr = rootGO.transform;
            }
        }
        else
        {
            curClip = null;
            rootTr  = null;
        }

        if (curClip != m_CurClip)
        {
            _OnCurrentClipChange(m_CurClip, curClip);
        }
        if (rootTr != m_ClipRoot)
        {
            _OnRootTransformChange(m_ClipRoot, rootTr);
        }
    }
Beispiel #12
0
    public override List <GameObject> updateDependencies(List <GameObject> newReferences, List <GameObject> oldReferences)
    {
        List <GameObject> lsFlagToKeep = new List <GameObject>();

        if (!obj)
        {
            return(lsFlagToKeep);
        }
        for (int i = 0; i < oldReferences.Count; i++)
        {
            if (oldReferences[i] == obj)
            {
                string    componentName = component.GetType().Name;
                Component _component    = newReferences[i].GetComponent(componentName);

                // missing component
                if (!_component)
                {
                    Debug.LogWarning("Animator: Property Track component '" + componentName + "' not found on new reference for GameObject '" + obj.name + "'. Duplicate not replaced.");
                    lsFlagToKeep.Add(oldReferences[i]);
                    return(lsFlagToKeep);
                }
                // missing property
                if (RCall.GetPropertyInfo(_component.GetType(), propertyName) == null)
                {
                    Debug.LogWarning("Animator: Property Track property '" + propertyName + "' not found on new reference for GameObject '" + obj.name + "'. Duplicate not replaced.");
                    lsFlagToKeep.Add(oldReferences[i]);
                    return(lsFlagToKeep);
                }

                obj       = newReferences[i];
                component = _component;
                break;
            }
        }
        return(lsFlagToKeep);
    }
Beispiel #13
0
        void OnGUI()
        {
            EditorGUILayout.LabelField("Set the Roots:");
            for (int i = 0; i < m_Roots.Count; ++i)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginChangeCheck();
                    var root = (Transform)EditorGUILayout.ObjectField(m_Roots[i], typeof(Transform), true);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_Roots[i] = root;
                    }
                    if (EUtil.Button("-", "delete entry", Color.red, GUILayout.Width(20f)))
                    {
                        m_Roots.RemoveAt(i);
                        GUIUtility.ExitGUI();
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(40f);
                if (GUILayout.Button("Add Root Entry"))
                {
                    m_Roots.Add(null);
                }
                GUILayout.Space(40f);
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(5f);

            if (GUILayout.Button(m_baking ? "Baking" : "Not Baking", EditorStyles.toolbarButton))
            {
                m_baking = !m_baking;

                if (m_baking)
                {
                    m_Trs.Clear();
                    foreach (var oneRoot in m_Roots)
                    {
                        for (var ie = oneRoot.GetRecurEnumerator(); ie.MoveNext();)
                        {
                            m_Trs.Add(ie.Current);
                        }
                    }

                    m_TrsArr = m_Trs.ToArray();
                    m_uaw    = EUtil.GetUnityAnimationWindow();
                    if (null == m_uaw)
                    {
                        m_baking = false;
                    }
                }
            }

            if (!m_baking)
            {
                EditorWindow uaw = (EditorWindow)EUtil.GetUnityAnimationWindow();
                if (uaw == null)
                {
                    EditorGUIUtility.ExitGUI();
                }
                object uawstate = EUtil.GetUnityAnimationWindowState(uaw);
                if (uawstate == null)
                {
                    EditorGUIUtility.ExitGUI();
                }
                var clip = RCall.GetField("UnityEditorInternal.AnimationWindowState",
                                          "m_ActiveAnimationClip", uawstate) as AnimationClip;
                if (clip == null)
                {
                    EditorGUIUtility.ExitGUI();
                }

                GUILayout.Space(5f);

                if (GUILayout.Button(new GUIContent("Compress Angles", "Only use this method on a clips full of keyframes"), EditorStyles.toolbarButton))
                {
                    _NormalizeRotationsInClip(uawstate, clip);
                }
            }
        }
Beispiel #14
0
        private void _NormalizeRotationsInClip(object uawstate, AnimationClip clip)
        {
            //float interval = 1 / clip.frameRate;
            IList allCurves = (IList)RCall.GetProp("UnityEditorInternal.AnimationWindowState", "allCurves", uawstate);

            foreach (var oneUAWCurve in allCurves)
            {
                EditorCurveBinding oneBinding = (EditorCurveBinding)RCall.GetProp("UnityEditorInternal.AnimationWindowCurve", "binding", oneUAWCurve);
                string             prop       = oneBinding.propertyName;
                string[]           parts      = prop.Split('.');
                if (parts.Length != 2)
                {
                    continue;
                }

                string main = parts[0];
                //string acc = parts[1];
                if (main == "localEulerAnglesRaw" || main == "localEulerAnglesBaked")
                {
                    AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, oneBinding);
                    var            keys  = curve.keys;

                    ////////////////////
                    // 1. normalize the first key to [-PI, PI], get the delta, and apply delta on all other keys in this curve
                    // 2. ensure the abs distance between each keyframe is less than 360 deg
                    ////////////////////

                    // 1
                    if (keys.Length == 0)
                    {
                        continue;
                    }

                    {
                        float oldV  = keys[0].value;
                        float newV  = Misc.NormalizeAnglePI(oldV);
                        float delta = newV - oldV;

                        // apply delta to all keyframes
                        for (int i = 0; i < keys.Length; ++i)
                        {
                            var k = keys[i];
                            k.value    += delta;
                            k.inTangent = k.outTangent = 0;
                            keys[i]     = k;
                        }
                    }

                    // 2
                    for (int i = 0; i < keys.Length - 1; ++i)
                    {
                        var k0 = keys[i];
                        var k1 = keys[i + 1];

                        float delta = (k1.value - k0.value) % 360f;
                        k1.value = k0.value + delta;

                        keys[i + 1] = k1;
                    }

                    curve.keys = keys;
                    AnimationUtility.SetEditorCurve(clip, oneBinding, curve);
                }
            }
        }
Beispiel #15
0
    // public method

    #endregion "public method"

    #region "private method"
    // private method

    private void _ConvertAnim(string newClipAssetPath)
    {
        // 0. prepare
        if (!m_Animator.isHuman)
        {
            Dbg.LogWarn("MuscleClipConverterEditor._ConvertAnim: Need to change to Humanoid rig first!");
            return;
        }

        m_SMR = m_Animator.GetComponentInChildren <SkinnedMeshRenderer>();
        if (m_SMR == null)
        {
            Dbg.LogWarn("MuscleClipConverterEditor._ConvertAnim: failed to find SMR under {0}", m_Animator.name);
            return;
        }

        m_Animator.Update(0);
#if !U5
        var ainfos = m_Animator.GetCurrentAnimationClipState(0); //only effect after Update is called
#else
        var ainfos = m_Animator.GetCurrentAnimatorClipInfo(0);   //only effect after Update is called
#endif
        AnimationClip         clip        = ainfos[0].clip;
        AnimationClipSettings clipSetting = AnimationUtility.GetAnimationClipSettings(clip);

        //{//debug
        //    var bindings = AnimationUtility.GetCurveBindings(clip);
        //    foreach( var b in bindings)
        //    {
        //        Dbg.Log("path: {0}, prop: {1}", b.path, b.propertyName);
        //    }
        //}

        Transform animatorTr = m_Animator.transform;
        Transform hipsBone   = null;
        CurveDict curveDict  = new CurveDict();

        float SAMPLE_RATE = clip.frameRate;
        float clipLen     = clip.length;

        Matrix4x4 animatorInitW2LMat = animatorTr.worldToLocalMatrix;
        Matrix4x4 hipsInitW2LMat     = Matrix4x4.identity;

        List <Transform> boneLst = new List <Transform>();
        for (HumanBodyBones boneIdx = 0; boneIdx < HumanBodyBones.LastBone; ++boneIdx)
        {
            Transform tr = m_Animator.GetBoneTransform(boneIdx);
            //Dbg.Log("Map: {0}->{1}", boneIdx, tr);
            if (tr != null)
            {
                boneLst.Add(tr);
                if (boneIdx == HumanBodyBones.Hips)
                {
                    hipsBone       = tr;
                    hipsInitW2LMat = hipsBone.parent.worldToLocalMatrix;
                    //clipSetting.level = -hipsBone.localPosition.y; // set Y offset
                    clipSetting.keepOriginalPositionY = false; //use RootNode position
                }
            }
        }
        Transform[] bones = boneLst.ToArray();

        // init curves for each bone
        for (int idx = 0; idx < bones.Length; ++idx)
        {
            Transform oneBone = bones[idx];
            string    trPath  = AnimationUtility.CalculateTransformPath(oneBone, animatorTr);

            var curves = new _Curves();
            curves.relPath = trPath;

            curveDict.Add(oneBone, curves);
        }

        // init rootmotion curve
        {
            var curves = new _Curves();
            curveDict.Add(animatorTr, curves);
        }

        AnimatorStateInfo curStateInfo = m_Animator.GetCurrentAnimatorStateInfo(0);
        float             nt           = curStateInfo.normalizedTime;
        m_Animator.Update(-nt * clipLen); //revert to 0 time

        {                                 // 1. bake animation info into curve on all bones transform
            float time      = 0f;
            float deltaTime = 1f / (SAMPLE_RATE);
            for (;
                 time <= clipLen || Mathf.Approximately(time, clipLen);
                 )
            {
                //Dbg.Log("nt = {0}", m_Animator.GetCurrentAnimatorStateInfo(0).normalizedTime);

                // bone
                for (int idx = 0; idx < bones.Length; ++idx)
                {
                    Transform oneBone = bones[idx];
                    _Curves   curves  = curveDict[oneBone];

                    if (oneBone == hipsBone)
                    {
                        continue; //skip the HipsBone. This is to add rootMotion matrix on hips, so Legacy is right
                    }
                    Vector3    pos = oneBone.localPosition;
                    Quaternion rot = oneBone.localRotation;

                    curves.X.AddKey(time, rot.x);
                    curves.Y.AddKey(time, rot.y);
                    curves.Z.AddKey(time, rot.z);
                    curves.W.AddKey(time, rot.w);

                    curves.PX.AddKey(time, pos.x);
                    curves.PY.AddKey(time, pos.y);
                    curves.PZ.AddKey(time, pos.z);
                }

                // root motion process
                {
                    { //on Animator transform
                        Vector3 pos = /*animatorTr.localPosition*/ animatorTr.position;
                        Vector3 fwd = animatorTr.forward;
                        Vector3 up  = animatorTr.up;

                        _Curves rootMotionCurves = curveDict[animatorTr];
                        Vector3 lpos             = animatorInitW2LMat.MultiplyPoint(pos);
                        Vector3 lfwd             = animatorInitW2LMat.MultiplyVector(fwd);
                        Vector3 lup = animatorInitW2LMat.MultiplyVector(up);

                        Quaternion rot = Quaternion.LookRotation(lfwd, lup);

                        rootMotionCurves.X.AddKey(time, rot.x);
                        rootMotionCurves.Y.AddKey(time, rot.y);
                        rootMotionCurves.Z.AddKey(time, rot.z);
                        rootMotionCurves.W.AddKey(time, rot.w);

                        rootMotionCurves.PX.AddKey(time, lpos.x);
                        rootMotionCurves.PY.AddKey(time, lpos.y);
                        rootMotionCurves.PZ.AddKey(time, lpos.z);
                    }

                    { //on hips transform
                        if (hipsBone != null)
                        {
                            Vector3 pos = hipsBone.position;
                            Vector3 fwd = hipsBone.forward;
                            Vector3 up  = hipsBone.up;

                            _Curves hipsCurves = curveDict[hipsBone];
                            Vector3 lpos       = hipsInitW2LMat.MultiplyPoint(pos);
                            Vector3 lfwd       = hipsInitW2LMat.MultiplyVector(fwd);
                            Vector3 lup        = hipsInitW2LMat.MultiplyVector(up);

                            //Dbg.Log("time: {0}, lpos: {1}", time, lpos.ToString("F2"));

                            Quaternion rot = Quaternion.LookRotation(lfwd, lup);

                            hipsCurves.X.AddKey(time, rot.x);
                            hipsCurves.Y.AddKey(time, rot.y);
                            hipsCurves.Z.AddKey(time, rot.z);
                            hipsCurves.W.AddKey(time, rot.w);

                            hipsCurves.PX.AddKey(time, lpos.x);
                            hipsCurves.PY.AddKey(time, lpos.y);
                            hipsCurves.PZ.AddKey(time, lpos.z);
                        }
                    }
                }

                if (!Mathf.Approximately(time + deltaTime, clipLen))
                {
                    m_Animator.Update(deltaTime);
                    time += deltaTime;
                }
                else
                {
                    m_Animator.Update(deltaTime - 0.005f); //keep it in the range, if go beyond, something bad could happen
                    time += deltaTime - 0.005f;
                }
            }
        } //end of 1.


        { // 2. set animation clip and store in AssetDatabase
            AnimationClip newClip = new AnimationClip();
            newClip.frameRate   = SAMPLE_RATE;
            newClip.localBounds = clip.localBounds;

            // set bone curves
            for (var ie = curveDict.GetEnumerator(); ie.MoveNext();)
            {
                var curves = ie.Current.Value;
                if (ie.Current.Key == animatorTr)
                { //root motion
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionT.x", curves.PX);
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionT.y", curves.PY);
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionT.z", curves.PZ);

                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionQ.x", curves.X);
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionQ.y", curves.Y);
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionQ.z", curves.Z);
                    newClip.SetCurve(curves.relPath, typeof(Animator), "MotionQ.w", curves.W);
                }
                else
                {
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localRotation.x", curves.X);
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localRotation.y", curves.Y);
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localRotation.z", curves.Z);
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localRotation.w", curves.W);

                    newClip.SetCurve(curves.relPath, typeof(Transform), "localPosition.x", curves.PX);
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localPosition.y", curves.PY);
                    newClip.SetCurve(curves.relPath, typeof(Transform), "localPosition.z", curves.PZ);
                }
            }

            // 2.1 copy the unmapped curves to new clip( not mapped by Muscle clip )
            _CopyOtherCurves(newClip, clip);

            // some setting work
            newClip.EnsureQuaternionContinuity();

#if !U5
            AnimationUtility.SetAnimationType(newClip, m_AnimType);
            RCall.CallMtd("UnityEditor.AnimationUtility", "SetAnimationClipSettings", null, newClip, clipSetting);
#else
            if (m_AnimType == ModelImporterAnimationType.Legacy)
            {
                newClip.legacy = true;
            }
            AnimationUtility.SetAnimationClipSettings(newClip, clipSetting);
#endif

            EUtil.SaveAnimClip(newClip, newClipAssetPath);

            EUtil.ShowNotification("Converted to: " + m_AnimType +
                                   (hipsBone != null ? ("\nroot=" + AnimationUtility.CalculateTransformPath(hipsBone, animatorTr)) : ""),
                                   3f
                                   );
        } //end of 2.

        // 3. clean job
        curveDict = null;
        AssetDatabase.SaveAssets();

        Dbg.Log("Converted: {0}", newClipAssetPath);
    }
Beispiel #16
0
    /// <summary>
    /// make the AnimEvent and EventGO to be matched
    /// maybe not one-one match, multiple animEvent could match same EventGO
    /// </summary>
    private void _MatchEventGOAndAnimEvent()
    {
        //////////////////////////////////////////////////
        //  1. for each AnimEvent, if there is not a corresponding eventGO, create it;
        //  2. for each eventGO, if there is not a corresponding AnimEvent, the delete the eventGO
        //////////////////////////////////////////////////

        //if( _IsAnimEventPopupOpen() )
        //{
        //    return; //don't execute matching if the AnimEventPopup is open
        //}

        // create a Dictionary for eventGO
        for (int idx = 0; idx < m_evtGoRoot.childCount; ++idx)
        {
            Transform ctr = m_evtGoRoot.GetChild(idx);
            m_evtGORefDict[ctr] = false;
        }

        // get the AnimEvent list
        AnimationEvent[] events = AnimationUtility.GetAnimationEvents(m_CurClip);

        // step 1
        for (int idx = 0; idx < events.Length; ++idx)
        {
            AnimationEvent evt      = events[idx];
            string         goName   = evt.stringParameter;
            string         funcName = evt.functionName;

            if (goName == null)
            {
                Dbg.LogWarn("CCEditor._MatchEventGOAndAnimEvent: found an event not specifying the GOName, at time: {0}", evt.time);
                ArrayUtility.RemoveAt(ref events, idx);
                --idx;
            }

            Transform oneTr = m_evtGoRoot.Find(goName);
            if (null == oneTr)
            {
                //create the go
                GameObject newEvtGO = new GameObject(goName);
                Misc.AddChild(m_evtGoRoot, newEvtGO);
                Dbg.Log("Sync AnimEvent with EventGO: create EventGO for: {0}", goName);

                //add component according to the funcName, the init-work should be executed by the MB's awake() or start()
                //CC_EvtActions newAct = newEvtGO.AddComponent("CC_" + funcName) as CC_EvtActions;
                //Dbg.Assert(m_CC != null, "CCEditor._MatchEventGOAndAnimEvent: failed to get CutsceneController");
                //newAct.CC = m_CC;

                string tpName = "MH.CC_" + funcName;
                Type   tp     = RCall.GetTypeFromString(tpName);
                Dbg.Assert(tp != null, "CCEditor._MatchEventGOAndAnimEvent: failed to get type from string: {0}", tpName);
                CC_EvtActions newAct = newEvtGO.AddComponent(tp) as CC_EvtActions;
                Dbg.Assert(m_CC != null, "CCEditor._MatchEventGOAndAnimEvent: failed to get CutsceneController");
                newAct.CC = m_CC;
            }
            else
            {
                m_evtGORefDict[oneTr] = true; //this event go is ref-ed, don't delete it
            }
        }

        // step 2
        for (var ie = m_evtGORefDict.GetEnumerator(); ie.MoveNext();)
        {
            var  pr    = ie.Current;
            bool inUse = pr.Value;
            if (!inUse)
            {
                Transform tr = pr.Key;
                Dbg.Log("Sync AnimEvent with EventGO: delete EventGO: {0}", tr.name);
                GameObject.DestroyImmediate(tr.gameObject);
            }
        }

        m_evtGORefDict.Clear(); //clear the tmp data
    }
Beispiel #17
0
    public static Rect GetMainGameViewPosition()
    {
        object gv = GetMainGameView();

        return((Rect)RCall.GetPropertyInfo(gv.GetType(), "position").GetValue(gv, null));
    }
 public void setValueType(Type t)
 {
     if (t == typeof(bool))
     {
         valueType = (int)ValueType.Boolean;
     }
     else if (t == typeof(string))
     {
         valueType = (int)ValueType.String;
     }
     else if (t == typeof(char))
     {
         valueType = (int)ValueType.Char;
     }
     else if (t == typeof(int))
     {
         valueType = (int)ValueType.Integer;
     }
     else if (t == typeof(long))
     {
         valueType = (int)ValueType.Long;
     }
     else if (t == typeof(float))
     {
         valueType = (int)ValueType.Float;
     }
     else if (t == typeof(double))
     {
         valueType = (int)ValueType.Double;
     }
     else if (t == typeof(Vector2))
     {
         valueType = (int)ValueType.Vector2;
     }
     else if (t == typeof(Vector3))
     {
         valueType = (int)ValueType.Vector3;
     }
     else if (t == typeof(Vector4))
     {
         valueType = (int)ValueType.Vector4;
     }
     else if (t == typeof(Color))
     {
         valueType = (int)ValueType.Color;
     }
     else if (t == typeof(Rect))
     {
         valueType = (int)ValueType.Rect;
     }
     else if (t.IsArray)
     {
         valueType = (int)ValueType.Array;
     }
     //else if(t.BaseType.BaseType == typeof(UnityEngine.Object)) valueType = (int)ValueType.Object;
     else if (RCall.GetBaseType(RCall.GetBaseType(t)) == typeof(UnityEngine.Object))
     {
         valueType = (int)ValueType.Object;
     }
     else
     {
         valueType = (int)ValueType.Object;
     }
 }