Example #1
0
        /// <summary>
        /// Adds a reactor to the list
        /// </summary>
        /// <param name="rReactor">ReactorAction to add</param>
        public virtual void AddReactor(ReactorAction rReactor)
        {
            _Reactors.Add(rReactor);
            _ReactorDefinitions.Add(rReactor.Serialize());

            rReactor.Owner = this.gameObject;
            rReactor.Awake();
        }
Example #2
0
    /// <summary>
    /// Allows us to draw each item in the list
    /// </summary>
    /// <param name="rRect"></param>
    /// <param name="rIndex"></param>
    /// <param name="rIsActive"></param>
    /// <param name="rIsFocused"></param>
    private void DrawReactorListItem(Rect rRect, int rIndex, bool rIsActive, bool rIsFocused)
    {
        if (rIndex < mTarget._Reactors.Count)
        {
            ReactorAction lItem = mTarget._Reactors[rIndex];
            if (lItem == null)
            {
                EditorGUI.LabelField(rRect, "NULL");
                return;
            }

            rRect.y += 2;

            bool  lIsDirty    = false;
            float lHSpace     = 5f;
            float lFlexVSpace = rRect.width - lHSpace - lHSpace - 40f - lHSpace - 16f;

            string lType = BaseNameAttribute.GetName(lItem.GetType());

            EditorGUILayout.BeginHorizontal();

            Rect lTypeRect = new Rect(rRect.x, rRect.y, lFlexVSpace / 2f, EditorGUIUtility.singleLineHeight);
            EditorGUI.LabelField(lTypeRect, lType);

            Rect   lNameRect = new Rect(lTypeRect.x + lTypeRect.width + lHSpace, lTypeRect.y, lFlexVSpace / 2f, EditorGUIUtility.singleLineHeight);
            string lNewName  = EditorGUI.TextField(lNameRect, lItem.Name);
            if (lNewName != lItem.Name)
            {
                lIsDirty   = true;
                lItem.Name = lNewName;
            }

            Rect  lPriorityRect = new Rect(lNameRect.x + lNameRect.width + lHSpace, lNameRect.y, 40f, EditorGUIUtility.singleLineHeight);
            float lNewPriority  = EditorGUI.FloatField(lPriorityRect, lItem.Priority);
            if (lNewPriority != lItem.Priority)
            {
                lIsDirty       = true;
                lItem.Priority = lNewPriority;
            }

            Rect lIsEnabledRect = new Rect(lPriorityRect.x + lPriorityRect.width + lHSpace, lPriorityRect.y, 16f, 16f);
            bool lNewIsEnabled  = EditorGUI.Toggle(lIsEnabledRect, lItem.IsEnabled);
            if (lNewIsEnabled != lItem.IsEnabled)
            {
                lIsDirty        = true;
                lItem.IsEnabled = lNewIsEnabled;
            }

            EditorGUILayout.EndHorizontal();

            // Update the item if there's a change
            if (lIsDirty)
            {
                mIsDirty = true;
                mTarget._ReactorDefinitions[rIndex] = lItem.Serialize();
            }
        }
    }
Example #3
0
    /// <summary>
    /// Renders the currently selected step
    /// </summary>
    /// <param name="rStep"></param>
    private bool DrawReactorDetailItem(ReactorAction rItem)
    {
        bool lIsDirty = false;

        if (rItem == null)
        {
            EditorGUILayout.LabelField("NULL");
            return(false);
        }

        if (rItem.Name.Length > 0)
        {
            EditorHelper.DrawSmallTitle(rItem.Name.Length > 0 ? rItem.Name : "Actor Core Reactor");
        }
        else
        {
            string lName = BaseNameAttribute.GetName(rItem.GetType());
            EditorHelper.DrawSmallTitle(lName.Length > 0 ? lName : "Actor Core Reactor");
        }

        string lDescription = BaseDescriptionAttribute.GetDescription(rItem.GetType());

        if (lDescription.Length > 0)
        {
            EditorHelper.DrawInspectorDescription(lDescription, MessageType.None);
        }

        if (EditorHelper.TextField("Name", "Friendly name of the reactor", rItem.Name, mTarget))
        {
            lIsDirty   = true;
            rItem.Name = EditorHelper.FieldStringValue;
        }

        // Render out the Reactor specific inspectors
        bool lIsReactorDirty = rItem.OnInspectorGUI(mTargetSO, mTarget);

        if (lIsReactorDirty)
        {
            lIsDirty = true;
        }

        if (lIsDirty)
        {
            mTarget._ReactorDefinitions[mReactorList.index] = rItem.Serialize();
        }

        return(lIsDirty);
    }
Example #4
0
    /// <summary>
    /// Allows us to add to a list
    /// </summary>
    /// <param name="rList"></param>
    private void OnReactorListItemAdd(ReorderableList rList)
    {
        if (mReactorIndex >= mReactorTypes.Count)
        {
            return;
        }

        ReactorAction lItem = Activator.CreateInstance(mReactorTypes[mReactorIndex]) as ReactorAction;

        lItem.Owner = mTarget.gameObject;

        mTarget._Reactors.Add(lItem);
        mTarget._ReactorDefinitions.Add(lItem.Serialize());

        mReactorList.index = mTarget._Reactors.Count - 1;
        OnReactorListItemSelect(rList);

        mIsDirty = true;
    }
Example #5
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);
            }

            // CDL 07/27/2018 - keep track of any invalid reactor definitions
            List <int> lInvalidDefinitions = new List <int>();

            // We need to match the definitions to the item
            for (int i = 0; i < lDefCount; i++)
            {
                string   lDefinition     = _ReactorDefinitions[i];
                JSONNode lDefinitionNode = JSONNode.Parse(lDefinition);
                if (lDefinitionNode == null)
                {
                    continue;
                }

                string lTypeString = lDefinitionNode["__Type"].Value;

                // CDL 07/27/2018 - Use AssemblyHelper.ResolveType() intead so that the Type can still
                // be obtained if the reactor was serialized as belonging to a different assembly
                bool lUpdateType;
                Type lType = AssemblyHelper.ResolveType(lTypeString, out lUpdateType);
                if (lType == null)
                {
                    // CDL 07/27/2018 - save this definition for removal afterwards, as we can't resolve the Type from any assembly.
                    lInvalidDefinitions.Add(i);
                    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);

                    // CDL 07/27/2018 - update the serialized Type if necessary
                    if (lUpdateType)
                    {
                        _ReactorDefinitions[i] = lReactor.Serialize();
                    }
                }
            }

            // CDL 07/27.2018 - Clean up any invalid Motion Definitions
            // this is causing an error, but maybe not needed, as I don't think there are
            // many people who have been using custom reactors
            //if (lInvalidDefinitions.Count > 0)
            //{
            //    for (int i = 0; i < lInvalidDefinitions.Count; i++)
            //    {
            //        int lIndex = lInvalidDefinitions[i];
            //        _ReactorDefinitions.RemoveAt(lIndex);
            //    }
            //}

            // 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();
            }
        }