Esempio n. 1
0
        /// <summary>
        /// Cache the state of all actors related to this event.
        /// </summary>
        /// <returns>All the revert info related to this event.</returns>
        public RevertInfo[] CacheState()
        {
            List <Transform>  actors  = new List <Transform>(GetActors());
            List <RevertInfo> reverts = new List <RevertInfo>();

            foreach (Transform go in actors)
            {
                if (go != null)
                {
                    Component b = go.GetComponent(Behaviour.GetType()) as Component;
                    if (b != null)
                    {
                        bool value;
                        if (ReflectionHelper.UseCodeGen)
                        {
                            value = (bool)ComponentReflectionExt.FastGetter(Behaviour, "enabled");
                        }
                        else
                        {
                            PropertyInfo pi = ReflectionHelper.GetProperty(Behaviour.GetType(), "enabled");
                            value = (bool)pi.GetValue(b, null);
                        }

                        reverts.Add(new RevertInfo(this, Behaviour, "enabled", value));
                    }
                }
            }

            return(reverts.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// Reverse trigger this event and Enable the chosen Behaviour.
        /// </summary>
        /// <param name="actor">The actor to perform the behaviour enable on.</param>
        public override void Reverse(GameObject actor)
        {
            Component b = actor.GetComponent(Behaviour.GetType()) as Component;

            if (b != null)
            {
                if (ReflectionHelper.UseCodeGen)
                {
                    ComponentReflectionExt.FastSetter(Behaviour, "enabled", true);
                    return;
                }

                PropertyInfo fieldInfo = ReflectionHelper.GetProperty(Behaviour.GetType(), "enabled");
                fieldInfo.SetValue(b, true, null);
            }
        }
Esempio n. 3
0
        internal object getCurrentValue(Component component)
        {
#if PROFILE_FILE
            Profiler.BeginSample("MemberClipCurveData.getCurrentValue");
#endif // PROFILE_FILE
            if (component == null || this.PropertyName == string.Empty)
            {
#if PROFILE_FILE
                Profiler.EndSample();
#endif // PROFILE_FILE
                return(null);
            }
            object value = null;

            if (ReflectionHelper.UseCodeGen)
            {
                value = ComponentReflectionExt.FastGetter(component, this.PropertyName);
#if PROFILE_FILE
                Profiler.EndSample();
#endif // PROFILE_FILE
                return(value);
            }


            Type type = component.GetType();
            if (this.IsProperty)
            {
                PropertyInfo propertyInfo = ReflectionHelper.GetProperty(type, this.PropertyName);
#if !UNITY_IOS
                value = propertyInfo.GetValue(component, null);
#else
                value = propertyInfo.GetGetMethod().Invoke(component, null);
#endif
            }
            else
            {
                FieldInfo fieldInfo = ReflectionHelper.GetField(type, this.PropertyName);
                value = fieldInfo.GetValue(component);
            }
#if PROFILE_FILE
            Profiler.EndSample();
#endif // PROFILE_FILE
            return(value);
        }
Esempio n. 4
0
        public object GetCurrentValue(Component component, string propertyName, bool isProperty)
        {
#if PROFILE_FILE
            Profiler.BeginSample("CinemaActorClipCurve.GetCurrentValue");
#endif // PROFILE_FILE
            if (component == null || propertyName == string.Empty)
            {
#if PROFILE_FILE
                Profiler.EndSample();
#endif // PROFILE_FILE
                return(null);
            }

            object value = null;

            if (ReflectionHelper.UseCodeGen)
            {
                value = ComponentReflectionExt.FastGetter(component, propertyName);
#if PROFILE_FILE
                Profiler.EndSample();
#endif // PROFILE_FILE
                return(value);
            }

            Type type = component.GetType();
            if (isProperty)
            {
                PropertyInfo propertyInfo = ReflectionHelper.GetProperty(type, propertyName);
                value = propertyInfo.GetValue(component, null);
            }
            else
            {
                FieldInfo fieldInfo = ReflectionHelper.GetField(type, propertyName);
                value = fieldInfo.GetValue(component);
            }
#if PROFILE_FILE
            Profiler.EndSample();
#endif // PROFILE_FILE
            return(value);
        }
        /// <summary>
        /// Cache the initial state of the curve clip manipulated values.
        /// </summary>
        /// <returns>The Info necessary to revert this clip.</returns>
        public RevertInfo[] CacheState()
        {
#if PROFILE_FILE
            Profiler.BeginSample("CinemaMultiActorCurveClip.CacheState");
#endif // PROFILE_FILE
            List <RevertInfo> reverts = new List <RevertInfo>();
            var actorCount            = Actors.Count;
            var compCount             = Components.Count;
            var propertyCount         = Properties.Count;
            for (int i = 0; i < actorCount; i++)
            {
                if (i >= compCount || i >= propertyCount)
                {
                    continue;
                }

                var component = Components[i];
                var property  = Properties[i];
                if (component != null && property != null && property != "None")
                {
                    if (ReflectionHelper.UseCodeGen)
                    {
                        var value = ComponentReflectionExt.FastGetter(component, property);
                        reverts.Add(new RevertInfo(this, component, property, value));
                    }
                    else
                    {
                        PropertyInfo propertyInfo = ReflectionHelper.GetProperty(component.GetType(), property);
                        reverts.Add(new RevertInfo(this, component, property,
                                                   propertyInfo.GetValue(component, null)));
                    }
                }
            }
#if PROFILE_FILE
            Profiler.EndSample();
#endif // PROFILE_FILE
            return(reverts.ToArray());
        }
Esempio n. 6
0
        /// <summary>
        /// Sample the curve clip at the given time.
        /// </summary>
        /// <param name="time">The time to evaulate for.</param>
        public void SampleTime(float time)
        {
#if PROFILE_FILE
            Profiler.BeginSample("CinemaActorClipCurve.SampleTime");
#endif // PROFILE_FILE
            var actor = ActorTransform;
            if (actor == null)
            {
#if PROFILE_FILE
                Profiler.EndSample();
#endif // PROFILE_FILE
                return;
            }
            if (Firetime <= time && time <= Firetime + Duration)
            {
                var list   = CurveData;
                var length = list.Count;
                for (var i = 0; i < length; i++)
                {
                    var memberData = list[i];
                    if (memberData.Type == string.Empty || memberData.PropertyName == string.Empty)
                    {
                        continue;
                    }

                    Transform transformComp = null;
                    Component component     = null;
                    if (memberData.Type.Equals("Transform"))
                    {
                        transformComp = actor;
                        component     = transformComp;
                    }
                    else
                    {
                        component = GetActorComponent(memberData.Type, actor);
                    }

                    if (component == null)
                    {
                        continue;
                    }

#if PROFILE_FILE
                    Profiler.BeginSample("CinemaActorClipCurve.SampleTime.seg_SetProperty");
#endif // PROFILE_FILE
                    if (ReflectionHelper.UseCodeGen)
                    {
                        if (transformComp != null)
                        {
                            if (memberData.PropertyType == PropertyTypeInfo.Vector3)
                            {
                                transformComp.FastSetter(memberData.PropertyName, evaluateVector3(memberData, time));
                            }
                            else if (memberData.PropertyType == PropertyTypeInfo.Quaternion)
                            {
                                transformComp.FastSetter(memberData.PropertyName, evaluateQuaternion(memberData, time));
                            }
                        }
                        else
                        {
                            var camera = component as Camera;
                            if (camera != null)
                            {
                                switch (memberData.PropertyType)
                                {
                                case PropertyTypeInfo.Float:
                                case PropertyTypeInfo.Double:
                                    float v1 = (float)evaluateNumbber(memberData, time);
                                    camera.FastSetter(memberData.PropertyName, v1);
                                    break;

                                case PropertyTypeInfo.Int:
                                    int v2 = (int)evaluateNumbber(memberData, time);
                                    camera.FastSetter(memberData.PropertyName, v2);
                                    break;

                                case PropertyTypeInfo.Color:
                                    Color v3 = evaluateColor(memberData, time);
                                    camera.FastSetter(memberData.PropertyName, v3);
                                    break;

                                default:
                                    object result = evaluate(memberData, time);
                                    camera.FastSetter(memberData.PropertyName, result);
                                    break;
                                }
                            }
                            else
                            {
                                object result = evaluate(memberData, time);
                                ComponentReflectionExt.FastSetter(component, memberData.PropertyName, result);
                            }
                        }
                    }
                    else
                    {
                        object value         = evaluate(memberData, time);
                        Type   componentType = component.GetType();

                        if (memberData.IsProperty)
                        {
                            PropertyInfo propertyInfo = ReflectionHelper.GetProperty(componentType, memberData.PropertyName);
#if !UNITY_IOS
                            propertyInfo.SetValue(component, value, null);
#else
                            tempObjectArr[0] = value;
                            propertyInfo.GetSetMethod().Invoke(component, tempObjectArr);
#endif
                        }
                        else
                        {
                            FieldInfo fieldInfo = ReflectionHelper.GetField(componentType, memberData.PropertyName);
                            ;
                            fieldInfo.SetValue(component, value);
                        }
                    }
#if PROFILE_FILE
                    Profiler.EndSample();
#endif // PROFILE_FILE
                }
            }
#if PROFILE_FILE
            Profiler.EndSample();
#endif // PROFILE_FILE
        }
        public void SampleTime(float time)
        {
#if PROFILE_FILE
            Profiler.BeginSample("CinemaMultiActorCurveClip.SampleTime");
#endif // PROFILE_FILE
            if (Firetime <= time && time <= Firetime + Duration)
            {
                MemberClipCurveData data = CurveData[0];
                if (data == null)
                {
#if PROFILE_FILE
                    Profiler.EndSample();
#endif // PROFILE_FILE
                    return;
                }

                if (data.PropertyType == PropertyTypeInfo.None)
                {
#if PROFILE_FILE
                    Profiler.EndSample();
#endif // PROFILE_FILE
                    return;
                }

                var count = Components.Count;

                for (int i = 0; i < count; i++)
                {
                    object value = null;
                    switch (data.PropertyType)
                    {
                    case PropertyTypeInfo.Color:
                        Color c;
                        c.r   = data.Curve1.Evaluate(time);
                        c.g   = data.Curve2.Evaluate(time);
                        c.b   = data.Curve3.Evaluate(time);
                        c.a   = data.Curve4.Evaluate(time);
                        value = c;
                        break;

                    case PropertyTypeInfo.Double:
                    case PropertyTypeInfo.Float:
                    case PropertyTypeInfo.Int:
                    case PropertyTypeInfo.Long:
                        value = data.Curve1.Evaluate(time);
                        break;

                    case PropertyTypeInfo.Quaternion:
                        Quaternion q;
                        q.x   = data.Curve1.Evaluate(time);
                        q.y   = data.Curve2.Evaluate(time);
                        q.z   = data.Curve3.Evaluate(time);
                        q.w   = data.Curve4.Evaluate(time);
                        value = q;
                        break;

                    case PropertyTypeInfo.Vector2:
                        Vector2 v2;
                        v2.x  = data.Curve1.Evaluate(time);
                        v2.y  = data.Curve2.Evaluate(time);
                        value = v2;
                        break;

                    case PropertyTypeInfo.Vector3:
                        Vector3 v3;
                        v3.x  = data.Curve1.Evaluate(time);
                        v3.y  = data.Curve2.Evaluate(time);
                        v3.z  = data.Curve3.Evaluate(time);
                        value = v3;
                        break;

                    case PropertyTypeInfo.Vector4:
                        Vector4 v4;
                        v4.x  = data.Curve1.Evaluate(time);
                        v4.y  = data.Curve2.Evaluate(time);
                        v4.z  = data.Curve3.Evaluate(time);
                        v4.w  = data.Curve4.Evaluate(time);
                        value = v4;
                        break;
                    }
                    var component = Components[i];
                    var property  = Properties[i];
                    if (component != null && property != null && property != "None")
                    {
                        if (ReflectionHelper.UseCodeGen)
                        {
                            ComponentReflectionExt.FastSetter(component, property, value);
                        }
                        else
                        {
                            PropertyInfo propertyInfo = ReflectionHelper.GetProperty(component.GetType(), property);
                            propertyInfo.SetValue(component, value, null);
                        }
                    }
                }
            }
#if PROFILE_FILE
            Profiler.EndSample();
#endif // PROFILE_FILE
        }
Esempio n. 8
0
        void StartLua()
        {
            ComponentReflectionExt.Init();
            var luaBridge      = LBootApp.luaBridge;
            var runDebugScript = luaBridge.DoString("return rawget(_G, 'SCRIPT') == 'debug'");

            if (true.Equals(runDebugScript))
            {
                LogUtil.Debug("running debug scripts");
                var    fname        = "debug.lua";
                byte[] scriptSource = FileUtils.GetDataFromStreamingAssets(fname);
                luaBridge.DoBuffer(scriptSource, fname);
            }
            else
            {
                LogUtil.Debug("running compiled scripts");
                var    fname        = "cl.lc";
                byte[] scriptSource = FileUtils.GetDataFromStreamingAssets(fname);
                luaBridge.DoAesBuffer(scriptSource, fname, LBootApp.LUA_KEY, LBootApp.LUA_IV);
                luaBridge.Call("__main", new object[1] {
                    ""
                });
            }

// 4 times faster for FastGetter FastSetter than using reflection
//            var go = new GameObject("hello");
//            var t = go.transform;
//            t.position = Vector3.one;
//            var startTime = Time.realtimeSinceStartup;
//            object value = null;
//            for (var i = 0; i < 1000; i++)
//            {
//                var positionProperty = ReflectionHelper.GetProperty(t.GetType(), "position");
//                value = positionProperty.GetValue(t, null);
//            }
//            Debug.LogError("Reflection getter position=" + value.ToString());
//            var time = Time.realtimeSinceStartup;
//            Debug.LogError("reflection getter duration = " + ((time - startTime) * 1000).ToString() + "(ms)");
//
//            startTime = Time.realtimeSinceStartup;
//
//            for (var i = 0; i < 1000; i++)
//            {
//                 value = ComponentReflectionExt.FastGetter(t, "position");
//            }
//            Debug.LogError("FastGetter position=" + value.ToString());
//
//            time = Time.realtimeSinceStartup;
//            Debug.LogError("Component FastGetter duration = " + ((time - startTime) * 1000).ToString() + "(ms)");
//
//            var angle = Vector3.one * 100;
//            startTime = Time.realtimeSinceStartup;
//            for (var i = 0; i < 1000; i++)
//            {
//                var positionProperty = ReflectionHelper.GetProperty(t.GetType(), "localEulerAngles");
//                positionProperty.SetValue(t, angle, null);
//            }
//
//            time = Time.realtimeSinceStartup;
//            Debug.LogError("reflection setter localEulerAngles=" + t.localEulerAngles.ToString());
//            Debug.LogError("reflection setter duration = " + ((time - startTime) * 1000).ToString() + "(ms)");
//            t.localEulerAngles = Vector3.one;
//            angle = new Vector3(199, 199, 199);
//            startTime = Time.realtimeSinceStartup;
//            for (var i = 0; i < 1000; i++)
//            {
//                ComponentReflectionExt.FastSetter(t, "localEulerAngles", angle);
//            }
//
//            time = Time.realtimeSinceStartup;
//            Debug.LogError("FastGetter localEulerAngles=" + t.localEulerAngles.ToString());
//            Debug.LogError("Component FastSetter duration = " + ((time - startTime) * 1000).ToString() + "(ms)");
        }