Exemplo n.º 1
0
        /// <summary>
        /// Processes the reactor definitions and update the reactors to match the definitions.
        /// </summary>
        public void InstantiateReactors()
        {
            int lDefCount = _ReactorDefinitions.Count;

            // First, remove any extra items that may exist
            for (int i = _Reactors.Count - 1; i >= lDefCount; i--)
            {
                _Reactors.RemoveAt(i);
            }

            // We need to match the definitions to the item
            for (int i = 0; i < lDefCount; i++)
            {
                string lDefinition = _ReactorDefinitions[i];

                Type lType = JSONSerializer.GetType(lDefinition);
                if (lType == null)
                {
                    continue;
                }

                ReactorAction lReactor = null;

                // If we don't have an item matching the type, we need to create one
                if (_Reactors.Count <= i || !lType.Equals(_Reactors[i].GetType()))
                {
                    lReactor       = Activator.CreateInstance(lType) as ReactorAction;
                    lReactor.Owner = this.gameObject;

                    if (_Reactors.Count <= i)
                    {
                        _Reactors.Add(lReactor);
                    }
                    else
                    {
                        _Reactors[i] = lReactor;
                    }
                }
                // Grab the matching item
                else
                {
                    lReactor = _Reactors[i];
                }

                // Fill the item with data from the definition
                if (lReactor != null)
                {
                    lReactor.Deserialize(lDefinition);
                }
            }

            // Allow each item to initialize now that it has been deserialized
            for (int i = 0; i < _Reactors.Count; i++)
            {
                _Reactors[i].Owner = this.gameObject;
                _Reactors[i].Awake();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes the effect definitions and updates the effects to match the definitions.
        /// </summary>
        public void InstantiateEffects()
        {
            int lDefCount = _EffectDefinitions.Count;

            // First, remove any extra motors that may exist
            for (int i = ActiveEffects.Count - 1; i >= lDefCount; i--)
            {
                ActiveEffects.RemoveAt(i);
            }

            // We need to match the motor definitions to the motors
            for (int i = 0; i < lDefCount; i++)
            {
                string lDefinition = _EffectDefinitions[i];

                Type lType = JSONSerializer.GetType(lDefinition);
                if (lType == null)
                {
                    continue;
                }

                ActorCoreEffect lEffect = null;

                // If don't have a motor matching the type, we need to create one
                if (ActiveEffects.Count <= i || !lType.Equals(ActiveEffects[i].GetType()))
                {
                    lEffect           = Activator.CreateInstance(lType) as ActorCoreEffect;
                    lEffect.ActorCore = this;

                    if (ActiveEffects.Count <= i)
                    {
                        ActiveEffects.Add(lEffect);
                    }
                    else
                    {
                        ActiveEffects[i] = lEffect;
                    }
                }
                // Grab the matching motor
                else
                {
                    lEffect = ActiveEffects[i];
                }

                // Fill the motor with data from the definition
                if (lEffect != null)
                {
                    lEffect.Deserialize(lDefinition);
                }
            }

            // Allow each motion to initialize now that his has been deserialized
            for (int i = 0; i < ActiveEffects.Count; i++)
            {
                ActiveEffects[i].Awake();
            }
        }