Пример #1
0
        /// <summary>
        /// Prepares array of empty LeiaViews, discarding previous if any
        /// Makes LeiaViews follow top-level Unity cameras "enabled" flag state
        /// </summary>
        public void SetViewCount(int count, bool forceUpdate = false)
        {
            this.Debug(string.Format("SetViewCount( {0}, {1})", count, forceUpdate));
            if (GetViewCount() == count && !forceUpdate)
            {
                return;
            }

            ClearViews();
            DisableUnnecessaryViews(count);

            _leiaViews = new LeiaView[count];

            for (var i = 0; i < count; i++)
            {
                var viewsParams = GetUnityCameraParams();

                _leiaViews[i] = new LeiaView(gameObject, viewsParams);
                // additional updates to LeiaViews occur in AbstractLeiaStateTemplate :: UpdateViews
            }

            ToggleLeiaViews(enabled);
        }
        private static void CopyEffectsToView(List <MonoBehaviour> effects, LeiaView view)
        {
            if (view == null || view.Object == null)
            {
                return;
            }

            var oldEffects = GetEffectsBehaviors(view.Object);

            foreach (var effect in effects)
            {
                if (effect == null)
                {
                    continue;
                }

                Component copy = null;

                for (int j = 0; j < oldEffects.Count; j++)
                {
                    if (effect.GetType() == oldEffects[j].GetType())
                    {
                        copy = oldEffects[j];
                        oldEffects.RemoveAt(j);
                        break;
                    }
                }

                if (copy == null)
                {
                    copy = view.Object.AddComponent(effect.GetType());
                }

                if (copy != null)
                {
                    var fields = effect.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                    for (int j = 0; j < fields.Length; j++)
                    {
                        if (fields[j].FieldType == typeof(Camera) && (fields[j].GetValue(effect) as Camera) == effect.GetComponent <Camera>())
                        {
                            // LeiaView GameObjects have their own Camera that should replace references to the root object's Camera
                            fields[j].SetValue(copy, view.Camera);
                        }
                        else if (fields[j].FieldType == typeof(UnityEngine.Rendering.CommandBuffer))
                        {
                            // exclude case where property is a CommandBuffer; CB fields should be managed by the Component which has a ref to the CB
                            continue;
                        }
                        else if (fields[j].FieldType == typeof(LeiaView))
                        {
                            // when a MonoBehaviour which is being copied from root cam to LeiaView has a ref to a LeiaView, set the LeiaView ref
                            fields[j].SetValue(copy, view);
                        }
                        else
                        {
                            // most general case - copy component's property's value from LeiaCamera to LeiaView
                            fields[j].SetValue(copy, fields[j].GetValue(effect));
                        }
                    }

                    //Generate onEnable
                    var behavior = copy as MonoBehaviour;
                    behavior.enabled = false;
                    behavior.enabled = true;
                }
            }

            RemoveEffects(oldEffects);
        }