Exemple #1
0
    public void Back()
    {
        if (currentObject.Equals(libraryMenu.taskMenu))
        {
            ShowGarage();
            return;
        }

        if (currentObject.Equals(libraryMenu.boosterMenu))
        {
            ShowTasksMenu();
        }
    }
Exemple #2
0
        public override bool Equals(object obj)
        {
            if (!(obj is MonoBehaviourPropertyValue value))
            {
                return(false);
            }

            return(MonoBehaviour.Equals(value.MonoBehaviour));
        }
Exemple #3
0
        /// <summary>
        /// Registers the specified component.
        /// </summary>
        /// <param name="component">The component.</param>
        public void Register(MonoBehaviour component)
        {
            if (component == null || component.Equals(null))
            {
                return;
            }

            var id = component.GetInstanceID();

            if (!_components.ContainsKey(id))
            {
                var type = component.GetType();
#if NETFX_CORE
                var aca = type.GetTypeInfo().GetCustomAttribute <ApexComponentAttribute>();
#else
                var aca = Attribute.GetCustomAttribute(type, typeof(ApexComponentAttribute)) as ApexComponentAttribute;
#endif
                if (aca == null)
                {
                    return;
                }

                if (_firstTime)
                {
                    component.hideFlags = HideFlags.HideInInspector;
                }

                var cinfo = new ComponentInfo
                {
                    component = component,
                    id        = id,
                    name      = type.Name.Replace("Component", string.Empty).ExpandFromPascal(),
                    isVisible = component.hideFlags != HideFlags.HideInInspector
                };

                _components.Add(id, cinfo);

                ComponentCategory cat;
                if (!_categories.TryGetValue(aca.category, out cat))
                {
                    cat = new ComponentCategory {
                        name = aca.category
                    };
                    _categories.Add(aca.category, cat);
                }

                cat.Add(cinfo);
                cinfo.category = cat;

                if (_initComplete)
                {
                    cat.Sort(new FunctionComparer <ComponentInfo>((a, b) => a.name.CompareTo(b.name)));
                    cat.isOpen = true;
                }
            }
        }
Exemple #4
0
    public override void gaxb_complete()
    {
        // If we're in live editor mode, we don't want to load controllers
        if (Application.isPlaying == false)
        {
            base.gaxb_complete();
            return;
        }

        if (gameObject != null)
        {
            gameObject.name = _class;
        }

        // check if there is another singleton of the same class as us, if so we exit early and destroy ourself
        MonoBehaviour existingSingleton = (MonoBehaviour)singletonInstances [_class];

        if (existingSingleton != null)
        {
            if (!existingSingleton.Equals(this))
            {
                GameObject.DestroyImmediate(this.gameObject);
                //Debug.LogFormat("existing singleton detected for {0}", _class);

                GameObject singletonGameObject = GameObject.Find(_class);
                if (singletonGameObject != null)
                {
                    singletonGameObject.SendMessage("MarkForCallStart");
                }

                if (_class != null)
                {
                    AttachAllAttributes(attributes, existingSingleton.GetComponent(Type.GetType(_class, true)));
                }

                return;
            }
        }


        if (controller == null && _class != null)
        {
            // Attach all of the PlanetUnity objects
            try {
                controller = (MonoBehaviour)gameObject.AddComponent(Type.GetType(_class, true));

                AttachAllElements(controller, Scope());
                AttachAllAttributes(attributes, controller);

                if (isSingleton())
                {
                    //Debug.Log("Saving instance class for: "+_class);
                    singletonInstances [_class] = controller;

                    gameObject.transform.SetParent(null);
                    UnityEngine.Object.DontDestroyOnLoad(gameObject);

                    ScheduleForStart();
                }
                else
                {
                    normalInstances [_class] = controller;
                }
            } catch (Exception e) {
                UnityEngine.Debug.Log("Controller error: " + e);
            }
        }

        if (controller != null)
        {
            try {
                // Attach all of the named GameObjects
                FieldInfo [] fields = controller.GetType().GetFields();
                foreach (FieldInfo field in fields)
                {
                    if (field.FieldType == typeof(GameObject))
                    {
                        GameObject [] pAllObjects = (GameObject [])Resources.FindObjectsOfTypeAll(typeof(GameObject));

                        foreach (GameObject pObject in pAllObjects)
                        {
                            if (pObject.name.Equals(field.Name))
                            {
                                field.SetValue(controller, pObject);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                UnityEngine.Debug.Log("Controller error: " + e);
            }

            foreach (PUNotification subscribe in Notifications)
            {
                NotificationCenter.addObserver(controller, subscribe.name, Scope(), subscribe.name);
            }
        }

        base.gaxb_complete();
    }
Exemple #5
0
    public override void gaxb_complete()
    {
        ScheduleForStart();

        bool shouldCallSingletonStart = false;

        // If we're in live editor mode, we don't want to load controllers
        if (Application.isPlaying == false)
        {
            base.gaxb_complete();
            return;
        }

        if (gameObject != null)
        {
            gameObject.name = _class;
        }

        if (singleton)
        {
            MonoBehaviour tempClassInstance = (MonoBehaviour)instances [_class];
            if (tempClassInstance != null && !tempClassInstance.Equals(this))
            {
                GameObject.DestroyImmediate(this.gameObject);
                controller = (MonoBehaviour)tempClassInstance;
                shouldCallSingletonStart = true;
            }
            else
            {
                MonoBehaviour.DontDestroyOnLoad(this.gameObject);
                this.gameObject.transform.SetParent(null);
            }
        }


        if (controller == null && _class != null)
        {
            // Attach all of the PlanetUnity objects
            try {
                controller = (MonoBehaviour)gameObject.AddComponent(Type.GetType(_class, true));

                AttachAllElements(controller, Scope());

                if (singleton)
                {
                    Debug.Log("Saving instance class for: " + _class);
                    instances[_class] = controller;
                }
                else
                {
                    normalInstances[_class] = controller;
                }
            }
            catch (Exception e) {
                UnityEngine.Debug.Log("Controller error: " + e);
            }
        }

        if (controller != null)
        {
            try {
                // Attach all of the named GameObjects
                FieldInfo[] fields = controller.GetType().GetFields();
                foreach (FieldInfo field in fields)
                {
                    if (field.FieldType == typeof(GameObject))
                    {
                        GameObject[] pAllObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject));

                        foreach (GameObject pObject in pAllObjects)
                        {
                            if (pObject.name.Equals(field.Name))
                            {
                                field.SetValue(controller, pObject);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                UnityEngine.Debug.Log("Controller error: " + e);
            }

            foreach (PUNotification subscribe in Notifications)
            {
                NotificationCenter.addObserver(controller, subscribe.name, Scope(), subscribe.name);
            }
        }

        if (shouldCallSingletonStart)
        {
            GameObject singletonGameObject = GameObject.Find(_class);
            if (singletonGameObject != null)
            {
                singletonGameObject.SendMessage("MarkForCallStart");
            }
        }

        base.gaxb_complete();
    }
Exemple #6
0
 protected bool Equals(MonoBehaviourPropertyValue other)
 {
     return(MonoBehaviour.Equals(other.MonoBehaviour));
 }
Exemple #7
0
        private void RenderAllFields(object currentObject)
        {
            FieldInfo[] fields = currentObject.GetType().GetFields(flags);
            foreach (FieldInfo field in fields)
            {
                using (new GUILayout.HorizontalScope("box"))
                {
                    GUILayout.Label($"[{field.FieldType.ToString().Split('.').Last()}]: {field.Name}", "options_label");

                    if (field.GetValue(currentObject) == null)
                    {
                        GUILayout.Box("Field is null");
                    }
                    else if (field.FieldType == typeof(bool))
                    {
                        bool boolVal = bool.Parse(GetValue(field, currentObject));
                        if (GUILayout.Button(boolVal.ToString()) && selectedMonoBehaviour.Equals(currentObject))
                        {
                            RegisterFieldChanges(field, selectedMonoBehaviour, !boolVal);
                        }
                    }
                    else if (field.FieldType.BaseType == typeof(MonoBehaviour))
                    {
                        if (GUILayout.Button(field.Name))
                        {
                            selectedMonoBehaviour = (MonoBehaviour)field.GetValue(currentObject);
                        }
                    }
                    else if (field.FieldType.BaseType == typeof(ScriptableObject))
                    {
                        using (new GUILayout.VerticalScope("box"))
                        {
                            RenderAllFields(field.GetValue(currentObject));
                        }
                    }
                    else if (field.FieldType == typeof(GameObject))
                    {
                        if (GUILayout.Button(field.Name))
                        {
                            selectedObject = (GameObject)field.GetValue(currentObject);
                            ActiveTab      = GetTab("GameObject").Value;
                        }
                    }
                    else if (field.FieldType == typeof(Text))
                    {
                        if (GUILayout.Button(field.Name))
                        {
                            selectedMonoBehaviour = (Text)field.GetValue(currentObject);
                        }
                    }
                    else if (field.FieldType == typeof(Texture) || field.FieldType == typeof(RawImage) || field.FieldType == typeof(Image))
                    {
                        Texture img;
                        if (field.FieldType == typeof(RawImage))
                        {
                            img = ((RawImage)field.GetValue(currentObject)).mainTexture;
                        }
                        else if (field.FieldType == typeof(Image))
                        {
                            img = ((Image)field.GetValue(currentObject)).mainTexture;
                        }
                        else
                        {
                            img = (Texture)field.GetValue(currentObject);
                        }

                        GUIStyle style = new GUIStyle("box");
                        style.fixedHeight = img.height * (250f / img.width);
                        style.fixedWidth  = 250;
                        GUILayout.Box(img, style);
                    }
                    else if (field.FieldType == typeof(NitroxId))
                    {
                        GUILayout.Box(((NitroxId)field.GetValue(currentObject)).ToString(), "options");
                    }
                    else if (field.FieldType == typeof(Int3))
                    {
                        Int3 value = (Int3)field.GetValue(currentObject);

                        GUILayout.Box(value.x + ", " + value.y + ", " + value.z, "options");
                    }
                    else if (field.FieldType == typeof(Base.Face?))
                    {
                        Base.Face?value = (Base.Face?)field.GetValue(selectedMonoBehaviour);

                        if (value.HasValue)
                        {
                            GUILayout.Box($"{value.Value.cell} {value.Value.direction}", "options");
                        }
                    }
                    else if (field.FieldType.IsEnum)
                    {
                        GUILayout.Box(field.GetValue(currentObject).ToString(), "options");
                    }
                    else if (selectedMonoBehaviour.Equals(currentObject))
                    {
                        try
                        {
                            Convert.ChangeType(field.GetValue(currentObject).ToString(), field.FieldType); //Check if convert work to prevent two TextFields
                            RegisterFieldChanges(field, selectedMonoBehaviour, Convert.ChangeType(GUILayout.TextField(GetValue(field, currentObject), "options"), field.FieldType));
                        }
                        catch
                        {
                            GUILayout.TextArea(GetValue(field, currentObject), "options");
                        }
                    }
                    else
                    {
                        GUILayout.TextArea(GetValue(field, currentObject), "options");
                    }
                }
            }
        }