Пример #1
0
        public override void Init()
        {
            //Cleaning out old listeners in case of reuse
            ServerMethod.RemoveAllListeners();

            if (ServerMethod.GetPersistentEventCount() == 0)
            {
                return;
            }

            //some reflection is required here.

            //reading prefab-based listener information:
            var        tabToLookup = ServerMethod.GetPersistentTarget(0);
            MethodInfo methodInfo  = UnityEventBase.GetValidMethodInfo(tabToLookup, ServerMethod.GetPersistentMethodName(0), new[] { typeof(string) });

            //disabling rigid listener
            ServerMethod.SetPersistentListenerState(0, UnityEventCallState.Off);

            //looking up a live instance of that tab we initially mapped listener to (in editor)
            var foundComponent = GetComponentInParent(tabToLookup.GetType());

            //making a dynamic copy of initial prefab-based listener
            UnityAction <string> execute = str => methodInfo.Invoke(foundComponent, new object[] { str });

            //applying a dynamic copy of initial prefab-based listener
            ServerMethod.AddListener(execute);
        }
        public override string GetSummary()
        {
            if (!string.IsNullOrEmpty(description))
            {
                return(description);
            }

            string summary = invokeType.ToString() + " ";

            switch (invokeType)
            {
            default:
            case InvokeType.Static:
                summary += staticEvent.GetPersistentEventCount();
                break;

            case InvokeType.DynamicBoolean:
                summary += booleanEvent.GetPersistentEventCount();
                break;

            case InvokeType.DynamicInteger:
                summary += integerEvent.GetPersistentEventCount();
                break;

            case InvokeType.DynamicFloat:
                summary += floatEvent.GetPersistentEventCount();
                break;

            case InvokeType.DynamicString:
                summary += stringEvent.GetPersistentEventCount();
                break;
            }

            return(summary + " methods");
        }
        void Start()
        {
#if UNITY_EDITOR
            dict.onChange += (k, a, b) => { UpdateValueStringWithDictionary(); };
#endif
            dict.onChange += (k, a, b) => {
                if (dictionaryTostringChangeListener.GetPersistentEventCount() > 0)
                {
                    string s = dict.Stringify(true);
                    //Debug.Log(s);
                    dictionaryTostringChangeListener.Invoke(s);
                }
            };
            dict.FunctionAssignIgnore();
#if TEST
            string[] mainStats = new string[] { "str", "con", "dex", "int", "wis", "cha" };
            int[]    scores    = { 8, 8, 18, 12, 9, 14 };
            for (int i = 0; i < mainStats.Length; ++i)
            {
                dict[mainStats[i]] = scores[i];
            }
            for (int i = 0; i < mainStats.Length; ++i)
            {
                string s = mainStats[i];
                dict.Set("_" + s, () => CalcStatModifier(s));
            }
            AddTo("cha", 4);
#endif
            dict.NotifyStart();
        }