예제 #1
0
    protected override void KGFAwake()
    {
        if (itsInstance == null)
        {
            itsInstance = this;
        }
        else
        {
            UnityEngine.Object.Destroy(this);
        }

        // Add all custom guis that are already there
        foreach (KGFICustomGUI aGui in KGFAccessor.GetObjects <KGFICustomGUI>())
        {
            Add(aGui);
        }
        // Add all future custom guis
        KGFAccessor.RegisterAddEvent <KGFICustomGUI>(OnAddCustomGui);
    }
예제 #2
0
 protected override void KGFAwake()
 {
     itsGUIs = KGFAccessor.GetObjects <KGFIGui2D>();
     KGFAccessor.RegisterAddEvent <KGFIGui2D>(OnRegisterKGFIGui2D);
     KGFAccessor.RegisterRemoveEvent <KGFIGui2D>(OnUnregisterKGFIGui2D);
 }
예제 #3
0
 void UpdateInternalList()
 {
     itsCustomGuiList = KGFAccessor.GetObjects <KGFICustomGUI>();
 }
예제 #4
0
        void TriggerRuntimeSearch(MonoBehaviour theCaller, object[] theRuntimeParameters)
        {
            Type aType = GetRuntimeType();

            if (aType == null)
            {
                LogError("could not find type", itsEventCategory, theCaller);
                return;
            }
            if (itsMethodName == null)
            {
                LogError("event has no selected method", itsEventCategory, theCaller);
                return;
            }

            // find method
            MethodInfo    aFoundMethod;
            MonoBehaviour aFoundComponent;

            if (!FindMethod(this, out aFoundMethod, out aFoundComponent))
            {
                LogError("Could not find method on object.", itsEventCategory, theCaller);
                return;
            }

            // convert parameters
            object [] aParametersList = null;
            if (GetDirectPassThroughMode())
            {
                aParametersList = theRuntimeParameters;
                // check parameter right types
            }
            else
            {
                // convert parameters set in this event
                ParameterInfo [] aParameterInfoArray = aFoundMethod.GetParameters();
                aParametersList = ConvertParameters(aParameterInfoArray, itsParameters);
                // convert linked parameters and add to the list
                for (int i = 0; i < itsParameters.Length; i++)
                {
                    if (GetIsParameterLinked(i))
                    {
                        int anIndex = GetParameterIndexWithType(GetParameterLink(i), aParameterInfoArray[i].ParameterType.FullName);
                        if (anIndex < theRuntimeParameters.Length)
                        {
                            aParametersList[i] = theRuntimeParameters[anIndex];
                        }
                        else
                        {
                            Debug.LogError("you did not give enough parameters");
                        }
                    }
                }
            }

//			// debug
//			foreach (object anObject in aParametersList)
//			{
//				print(" - "+anObject+ " / "+anObject.GetType());
//			}

            // call method
            List <MonoBehaviour> afoundObjectList = new List <MonoBehaviour>();

            try
            {
                if (aType.IsInterface || typeof(KGFObject).IsAssignableFrom(aType))
                {
                    // use fast kgfaccessor method
                    foreach (object anObject in KGFAccessor.GetObjects(aType))
                    {
                        MonoBehaviour aMonobehaviour = anObject as MonoBehaviour;
                        if (aMonobehaviour != null)
                        {
                            if (CheckRuntimeObjectName(aMonobehaviour))
                            {
                                aFoundMethod.Invoke(anObject, aParametersList);
                                afoundObjectList.Add(aMonobehaviour);
                            }
                        }
                    }
                }
                else if (!aType.IsInterface)
                {
                    foreach (object anObject in GameObject.FindObjectsOfType(aType))
                    {
                        MonoBehaviour aMonobehaviour = anObject as MonoBehaviour;
                        if (aMonobehaviour != null)
                        {
                            if (CheckRuntimeObjectName(aMonobehaviour))
                            {
                                aFoundMethod.Invoke(anObject, aParametersList);
                                afoundObjectList.Add(aMonobehaviour);
                            }
                        }
                    }
                }
            } catch (Exception e)
            {
                LogError("invoked method caused exception in event_generic:" + e, itsEventCategory, theCaller);
            }

            // log call
            List <string> aParamStringList = new List <string> ();

            if (aParametersList != null)
            {
                foreach (object aParam in aParametersList)
                {
                    aParamStringList.Add("" + aParam);
                }
            }

            foreach (MonoBehaviour aMonoBehaviour in afoundObjectList)
            {
                string aLogInfo = string.Format("{0}({1}): {2} ({3})", aMonoBehaviour.name, itsRuntimeObjectSearchType, aFoundMethod.Name, string.Join(",", aParamStringList.ToArray()));
                LogDebug(aLogInfo, itsEventCategory, theCaller);
            }
        }