コード例 #1
0
ファイル: MethodBinding.cs プロジェクト: BeauPrime/RuleScript
        private void Bind(InvocationTarget inTarget, IRSRuntimeEntity inEntity, IScriptContext inContext, ref object ioValue)
        {
            switch (inTarget)
            {
            case InvocationTarget.Entity:
                ioValue = inEntity;
                break;

            case InvocationTarget.Component:
                ioValue = inEntity?.GetRSComponent(ComponentType);
                break;

            case InvocationTarget.Context:
                ioValue = inContext;
                break;
            }
        }
コード例 #2
0
        /// <summary>
        /// Restores persistent data to the given runtime entity and its components.
        /// </summary>
        static public bool Restore(RSEnvironment inEnvironment, RSPersistEntityData inData, IRSRuntimeEntity inEntity, IReadOnlyList <IRSRuntimeComponent> inComponents, int inFlags)
        {
            if (inEntity == null)
            {
                return(false);
            }

            using (PooledList <IRSPersistListener> persistListeners = PooledList <IRSPersistListener> .Alloc())
            {
                IRSPersistListener entityPersistListener = inEntity as IRSPersistListener;
                if (entityPersistListener != null)
                {
                    entityPersistListener.OnPreRestore(inEnvironment);
                    persistListeners.Add(entityPersistListener);
                }

                inEntity.SetActiveWithoutNotify(inData.Active);
                inEntity.RuleTable?.Restore(inData.TableData);
                for (int i = 0, length = inData.ComponentData.Length; i < length; ++i)
                {
                    RSPersistComponentData componentData = inData.ComponentData[i];

                    RSComponentInfo componentInfo = inEnvironment.Library.GetComponent(componentData.ComponentType);
                    if (componentInfo == null)
                    {
                        continue;
                    }

                    IRSRuntimeComponent component = inEntity.GetRSComponent(componentInfo.OwnerType);
                    if (component == null)
                    {
                        continue;
                    }

                    if (inComponents != null)
                    {
                        bool bIncluded = false;
                        for (int allCompIdx = 0, allCompLength = inComponents.Count; allCompIdx < allCompLength; ++allCompIdx)
                        {
                            IRSRuntimeComponent includedComponent = inComponents[allCompIdx];
                            if (includedComponent == component)
                            {
                                bIncluded = true;
                                break;
                            }
                        }

                        if (!bIncluded)
                        {
                            continue;
                        }
                    }

                    IRSPersistListener componentListener = component as IRSPersistListener;
                    if (componentListener != null)
                    {
                        componentListener.OnPreRestore(inEnvironment);
                        persistListeners.Add(componentListener);
                    }

                    componentInfo.Restore(component, componentData, inEnvironment, inFlags);
                }

                IRSCustomPersistDataProvider customDataProvider = inEntity as IRSCustomPersistDataProvider;
                if (customDataProvider != null)
                {
                    customDataProvider.RestoreCustomPersistData(inData.CustomData, inFlags, inEnvironment);
                }

                foreach (var listener in persistListeners)
                {
                    listener.OnPostRestore(inEnvironment);
                }
            }

            return(true);
        }