Example #1
0
        private void CreateDrawLists()
        {
            foreach (var memberField in getters)
            {
                bool valid = memberField.Initialize();
                if (!valid)
                {
                    StratusDebug.LogError($"No member has been selected on the target {memberField.member.target.name}", this);
                    continue;
                }

                switch (memberField.visualizationMode)
                {
                case MemberVisualizationField.VisualizationMode.Scene:
                    AddToDrawList(memberField, sceneDrawList);
                    break;

                case MemberVisualizationField.VisualizationMode.Game:
                    AddToDrawList(memberField, gameDrawList);
                    break;

                case MemberVisualizationField.VisualizationMode.SceneGUI:
                    AddToDrawList(memberField, sceneGUIDrawList);
                    break;

                case MemberVisualizationField.VisualizationMode.GameGUI:
                    AddToDrawList(memberField, gameGUIDrawList);
                    break;

                default:
                    break;
                }
            }
        }
Example #2
0
        protected override IList <TreeViewItem> BuildRows(TreeViewItem root)
        {
            if (this.treeModel.root == null)
            {
                StratusDebug.LogError($"Tree model root is null. Was the data set?");
            }

            this.rows.Clear();
            // IF there's a search string, build the rows from it
            if (!string.IsNullOrEmpty(this.searchString))
            {
                this.Search(this.treeModel.root, this.searchString, this.rows);
            }
            // Build rows from the root
            else
            {
                if (this.treeModel.root.hasChildren)
                {
                    this.AddChildrenRecursive(this.treeModel.root, 0, this.rows);
                }
            }

            // The child parent information still has to be set for the rows
            // since the information is used by the treeview internal logic (navigation, dragging, etc)
            TreeView.SetupParentsAndChildrenFromDepths(this.rootItem, this.rows);

            return(this.rows);
        }
Example #3
0
        //------------------------------------------------------------------------/
        // Messages
        //------------------------------------------------------------------------/
        protected override void OnAwake()
        {
            if (type.Type == null)
            {
                StratusDebug.LogError("Type not set. Please select the Stratus.Event type to connect to!", this);
                return;
            }

            proxy = StratusEventProxy.Construct(source, eventScope, type, OnEvent, persistent, debug);
        }
Example #4
0
        public InputLayer Pop()
        {
            InputLayer layer = null;


            // If there's layers remaining, remove the topmost
            if (hasActiveLayers)
            {
                layer        = _layers.Pop();
                layer.active = false;
                layer.pushed = false;
            }

            bool queue = hasQueuedLayers &&
                         (!hasActiveLayers || (hasActiveLayers && !activeLayer.blocking));

            StratusDebug.Log($"Popped {layer}. Check queue? {queue}");

            // If there's still layers left
            if (queue)
            {
                // If there are queud layers
                // and the topmost is not blocking
                if (hasQueuedLayers)
                {
                    while (_queuedLayers.NotEmpty())
                    {
                        layer = _queuedLayers.Dequeue();
                        bool blocking = layer.blocking;
                        StratusDebug.Log($"Popped layer {layer}, blocking ? {blocking}");
                        Push(layer, !blocking);
                        if (blocking)
                        {
                            StratusDebug.Log($"Breaking");
                            break;
                        }
                    }
                }
            }

            // Update the current layer if its active
            if (hasActiveLayers)
            {
                if (activeLayer.pushed)
                {
                    ActivateInputLayer(activeLayer);
                }
                else
                {
                    StratusDebug.LogError("Layer not enabled???");
                }
            }

            return(layer);
        }
        //------------------------------------------------------------------------/
        // Methods: Public
        //------------------------------------------------------------------------/
        public void LoadState(string label)
        {
            if (!stateMap.ContainsKey(label))
            {
                StratusDebug.LogError($"The state {label} was not found!", this);
            }

            SerializedState state = stateMap[label];

            LoadState(state);
        }
        //public bool Add(KeyType key, ValueType value)
        //{
        //    if (dictionary.ContainsKey(key))
        //    {
        //        return false;
        //    }
        //    dictionary.Add(key, value);
        //    return true;
        //}

        public bool Add(ValueType value)
        {
            KeyType key = keyFunction(value);

            if (ContainsKey(key))
            {
                StratusDebug.LogError($"Item with {key} already exists in this collection!");
                return(false);
            }
            Add(key, value);
            return(true);
        }
        public static void ScrollToChildIfNotVisible(this ScrollRect scrollRect, RectTransform contentChild)
        {
            if (scrollRect.content != contentChild.parent)
            {
                StratusDebug.LogError($"Can only scroll to children of scrollRect's content {scrollRect.content}");
                return;
            }

            int   childIndex   = contentChild.transform.GetSiblingIndex();
            float targetValue  = 1f - ((float)childIndex / (float)scrollRect.content.transform.childCount);
            float currentValue = scrollRect.verticalNormalizedPosition;

            StratusDebug.Log($"Scrolling to {targetValue}");
            scrollRect.verticalNormalizedPosition = targetValue;
        }
Example #8
0
        private void AddExtension(int extensionTypeIndex)
        {
            Type extensionType = extensionTypes[extensionTypeIndex];

            IStratusExtensionBehaviour extension = target.gameObject.AddComponent(extensionType) as IStratusExtensionBehaviour;

            if (extension == null)
            {
                StratusDebug.LogError($"Failed to construct extension of type {extensionType.Name}");
                return;
            }

            StratusDebug.Log($"Adding extension {extensionType.Name}");
            target.Add(extension);
            Undo.RecordObject(target, extensionType.Name);
            serializedObject.ApplyModifiedProperties();

            this.SetExtensionIndex();
            this.RefreshExtensions();
        }
        private static void RecordEntry(History.Entry e)
        {
            history.entries.Add(e);
            switch (e.type)
            {
            case History.EntryType.Submit:
                StratusDebug.Log(e.text);
                break;

            case History.EntryType.Result:
                StratusDebug.Log(e.text);
                break;

            case History.EntryType.Warning:
                StratusDebug.LogWarning(e.text);
                break;

            case History.EntryType.Error:
                StratusDebug.LogError(e.text);
                break;
            }
            onEntry?.Invoke(e);
        }
Example #10
0
 /// <summary>
 /// Prints the given error message to the console
 /// </summary>
 /// <param name="value"></param>
 public static void LogError(this IStratusLogger logger, object value) => StratusDebug.LogError(value, logger, 2);
Example #11
0
 /// <summary>
 /// Prints the given error message to the console
 /// </summary>
 /// <param name="value"></param>
 public void LogError(object value) => StratusDebug.LogError(value, this, 2);
Example #12
0
 protected void Error(string msg, Behaviour trigger)
 {
     StratusDebug.LogError(ComposeLog(msg), trigger);
 }
Example #13
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Set the global variables
            this.drawIf = this.attribute as DrawIfAttribute;

            // Whether the condition has been met
            bool conditionMet = false;

            // The actual target needed
            object target     = property.GetParent <object>();
            Type   targetType = this.fieldInfo.ReflectedType;


            if (this.drawIf.predicate == PredicateMode.PropertyComparison)
            {
                //this.comparedMember = property.serializedObject.FindProperty(this.drawIf.comparedMemberName);
                this.comparedMember = property.serializedObject.FindProperty(this.drawIf.comparedMemberName);
                // Get the value of the compared field
                object comparedFieldValue = target.GetFieldOrPropertyValue <object>(this.drawIf.comparedMemberName);                // ( targetType.Getpro this.comparedMember.GetValue<object>();
                // References to the values as numeric types
                StratusNumeric numericComparedFieldValue = null;
                StratusNumeric numericComparedValue      = null;

                // Try to set the numeric types
                try
                {
                    numericComparedFieldValue = new StratusNumeric(comparedFieldValue);
                    numericComparedValue      = new StratusNumeric(this.drawIf.comparedValue);
                }
                catch (StratusNumericTypeExpectedException)
                {
                    if (this.drawIf.comparison != ComparisonType.Equals && this.drawIf.comparison != ComparisonType.NotEqual)
                    {
                        StratusDebug.LogError("The only comparsion types available to type '" + comparedFieldValue.GetType() + "' are Equals and NotEqual. (On object '" + property.serializedObject.targetObject.name + "')", null);
                        return;
                    }
                }
                // Compare the values to see if the condition has been met
                switch (this.drawIf.comparison)
                {
                case ComparisonType.Equals:
                    if (comparedFieldValue.Equals(this.drawIf.comparedValue))
                    {
                        conditionMet = true;
                    }

                    break;

                case ComparisonType.NotEqual:
                    if (!comparedFieldValue.Equals(this.drawIf.comparedValue))
                    {
                        conditionMet = true;
                    }

                    break;

                case ComparisonType.Greater:
                    if (numericComparedFieldValue > numericComparedValue)
                    {
                        conditionMet = true;
                    }

                    break;

                case ComparisonType.Lesser:
                    if (numericComparedFieldValue < numericComparedValue)
                    {
                        conditionMet = true;
                    }

                    break;

                case ComparisonType.LesserOrEqual:
                    if (numericComparedFieldValue <= numericComparedValue)
                    {
                        conditionMet = true;
                    }

                    break;

                case ComparisonType.GreaterOrEqual:
                    if (numericComparedFieldValue >= numericComparedValue)
                    {
                        conditionMet = true;
                    }

                    break;
                }
            }
            // Else if we are checking a predicate
            else if (this.drawIf.predicate == PredicateMode.Predicate)
            {
                // Method
                MethodInfo predicateMethod = targetType.GetMethod(this.drawIf.comparedMemberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (predicateMethod != null)
                {
                    conditionMet = (bool)predicateMethod.Invoke(target, null);
                }
                // Property
                else
                {
                    PropertyInfo predicateProperty = targetType.GetProperty(this.drawIf.comparedMemberName,
                                                                            BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetProperty);

                    if (predicateProperty != null)
                    {
                        conditionMet = (bool)predicateProperty.GetValue(target, null);
                    }
                    else
                    {
                        throw new System.Exception($"{this.fieldInfo.Name} , {this.fieldInfo.ReflectedType.GetNiceFullName()} : The type {targetType.GetNiceFullName()} is missing the boolean property {this.drawIf.comparedMemberName}");
                    }
                }
            }

            // The height of the property should be defaulted to the default height
            this.propertyHeight = EditorGUI.GetPropertyHeight(property);
            //propertyHeight = base.GetPropertyHeight(property, label);

            // If the condition is met, draw the field
            if (conditionMet)
            {
                //base.OnGUI(position, property, label);
                StratusEditorUtility.UseDefaultDrawer(position, property, label, fieldInfo.FieldType);
            }
            // Otherwise use the default ebhavior
            else
            {
                if (this.drawIf.defaultBehavior == PropertyDrawingType.ReadOnly)
                {
                    UnityEngine.GUI.enabled = false;
                    StratusEditorUtility.UseDefaultDrawer(position, property, label, targetType);
                    UnityEngine.GUI.enabled = true;
                }
                else
                {
                    this.propertyHeight = 0f;
                }
            }
        }