예제 #1
0
        public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label)
        {
            //can't run this in initialize because editor styles is null there
            if (style == null)
            {
                style = new GUIStyle(EditorStyles.popup);
                style.normal.textColor  = Color.blue;
                style.active.textColor  = Color.blue;
                style.focused.textColor = Color.blue;
            }

            guiRect.SetRect(position);

            ReflectedProperty curveProperty = property["curve"];

            if (curveProperty == null)
            {
                DrawHeaderBox(property, false, s_nullCurve);
                return;
            }

            ResponseCurve curve = curveProperty.Value as ResponseCurve;

            if (!property.IsExpanded)
            {
                DrawCollapsed(property, curve);
            }
            else
            {
                DrawExpanded(property, curve);
            }
        }
예제 #2
0
    static ResponseCurve[] GetCurvesFromSelection()
    {
        ArrayList curves = new ArrayList();

        if (Selection.activeTransform == null)
            return new ResponseCurve[0];

        foreach (MonoBehaviour behaviour in Selection.activeTransform.GetComponents(typeof(MonoBehaviour)))
        {
            FieldInfo[] myFieldInfo = behaviour.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            for(int i = 0; i < myFieldInfo.Length; i++)
            {
                if (myFieldInfo[i].FieldType == typeof(AnimationCurve))
                {
                    object curve = myFieldInfo[i].GetValue(behaviour);
                    if (curve != null)
                    {
                        ResponseCurve r = new ResponseCurve ();
                        r.field = myFieldInfo[i];
                        r.behaviour = behaviour;
                        curves.Add(r);
                    }
                }
            }
        }

        if (curves.Count != 0)
            return curves.ToArray(typeof(ResponseCurve)) as ResponseCurve[];
        else
            return new ResponseCurve[0];
    }
예제 #3
0
 private void DrawExpanded(ReflectedProperty property, ResponseCurve curve)
 {
     DrawHeaderBox(property, false, curve);
     property["curve"].Value = EditorGUIX.ResponseCurveField(guiRect.GetFieldRect(7), curve);
     guiRect.GetFieldRect();
     EditorGUIX.DrawProperties(guiRect.GetRect(), property, new[] { "curve" });
 }
        public override void GetTagData(byte[] iccData, int index, ICCHeader header)
        {
            //Number of channels (2 bytes)
            ChannelCount = HighEndianReader.GetUInt16(iccData, index, IsLittleEndian);
            //Count of measurement types (2 bytes)
            MeasurmentTypesCount = HighEndianReader.GetUInt16(iccData, index + 2, IsLittleEndian);
            //Offsets (4 bytes each)
            Offset = new int[MeasurmentTypesCount];
            int dataEntryPoint;

            for (int i = 0; i < MeasurmentTypesCount; i++)
            {
                dataEntryPoint = index + 4 + i * 4;
                Offset[i]      = (int)HighEndianReader.GetUint32(iccData, dataEntryPoint, IsLittleEndian);
            }
            //int end = idx + 4 + 4 * MeasurmentTypesCount; int c = 0;
            //for (int i = idx + 4; i < end; i += 4) { Offset[c] = (int)Helper.GetUInt32(i); c++; }
            //Response curve structures
            Curves = new ResponseCurve[MeasurmentTypesCount];
            for (int i = 0; i < MeasurmentTypesCount; i++)
            {
                dataEntryPoint = index - 8 + Offset[i];
                Curves[i]      = new ResponseCurve(iccData, dataEntryPoint, ChannelCount, IsLittleEndian);
            }
        }
        protected override void OnUpdate()
        {
            // var ecb = _endSimulationEcbSystem.CreateCommandBuffer().AsParallelWriter();

            Entities.WithAll <UnitAi, UnitAiDecision>()
            .ForEach((ref UnitAttackScore attackScore, in CrowdMember crowdMember, in CrowdMemberSystemState crowdMemberSystemState, in UnitAiDecision aiState) => {
                if (crowdMemberSystemState.prey != Entity.Null && (crowdMember.behavingPolicy | CrowdMemberBehavingPolicy.ALLOWED_ATTACK) == crowdMember.behavingPolicy)
                {
                    if (aiState.currentAction == UnitActionTypes.ATTACK)
                    {
                        attackScore.score = 1.0f;                                 // или сделать больше 1?
                    }
                    else
                    {
                        attackScore.score = ResponseCurve.Exponential(math.clamp(attackScore.score, 0.0f, 1.0f));
                    }

                    // TODO: отбалансить
                    if (crowdMemberSystemState.preyDistance < 2.5f)
                    {
                        attackScore.score += 0.25f;
                    }
                }
                else
                {
                    attackScore.score = 0.0f;
                }
            }).ScheduleParallel();
예제 #6
0
    void CurveSelection()
    {
        if (m_ResponseCurves.Length == 0)
        {
            GUI.Label(new Rect(20, 20, Screen.width - 40, Screen.height), "No Response Curve in selection.\n\nPlease select a game object with scripts containing\npublicly exposed animation curves");
            return;
        }

        string[] curveNames = new string[m_ResponseCurves.Length];
        for (int i = 0; i < m_ResponseCurves.Length; i++)
        {
            ResponseCurve curve = m_ResponseCurves[i];
            curveNames[i] = curve.field.Name;
        }

        m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition, GUILayout.Width(curveSelectionGridWidth), GUILayout.Height(Screen.height));
        GUI.changed      = false;
        m_SelectedCurve  = GUILayout.SelectionGrid(m_SelectedCurve, curveNames, 1, GUILayout.Width(curveSelectionGridWidth));
        GUILayout.EndScrollView();
        if (GUI.changed)
        {
            DisplayCurve(m_SelectedCurve);
        }

        Handles.color = Color.black;
        Handles.DrawLine(new Vector2(curveSelectionGridWidth, 0), new Vector2(curveSelectionGridWidth, Screen.height));
    }
예제 #7
0
        private static ResponseCurve ApplyResponseCurvePreset(string presetName, ResponseCurve input)
        {
            switch (presetName)
            {
            case "Linear":  return(ResponseCurve.CreateLinearCurve());

            case "2 Poly":  return(ResponseCurve.Create2PolyCurve());

            case "4 Poly":  return(ResponseCurve.Create4PolyCurve());

            case "6 Poly":  return(ResponseCurve.Create6PolyCurve());

            case "8 Poly":  return(ResponseCurve.Create8PolyCurve());

            case "-2 Poly": return(ResponseCurve.CreateInverted2PolyCurve());

            case "-4 Poly": return(ResponseCurve.CreateInverted4PolyCurve());

            case "-6 Poly": return(ResponseCurve.CreateInverted6PolyCurve());

            case "-8 Poly": return(ResponseCurve.CreateInverted8PolyCurve());

            default:
                return(input);
            }
        }
예제 #8
0
    //////////////////////////////////////////////////////////////////////////////////////
    //                                                                                  //
    //                                                                                  //
    //                                                                                  //
    //////////////////////////////////////////////////////////////////////////////////////
    public override void OnInspectorGUI()
    {
        Rect          currentInspacetorRect;
        ResponseCurve myTarget = (ResponseCurve)target;
        float         fMinInput, fMaxInput, fMinOutput, fMaxOutput; // mins and maxs inputs and outputs.
                                                                    // Will be used to normalize and paint within boundaries.
        float   fLastStepInput = 0;
        Vector2 position, size;

        currentInspacetorRect = EditorGUILayout.BeginVertical(GUILayout.Width(200), GUILayout.Height(100));

        DrawDefaultInspector();

        fMinInput = fMinOutput = float.MaxValue;
        fMaxInput = fMaxOutput = float.MinValue;
        for (int i = 0; i < myTarget.GetCurveDefinitionSize(); i++)
        {
            float fInput  = myTarget.GetCurveDefinitionInputAt(i);
            float fOutput = myTarget.GetValue(fInput);
            if (fMinInput > fInput)
            {
                fMinInput = fInput;
            }
            if (fMaxInput < fInput)
            {
                fMaxInput = fInput;
            }
            if (fMinOutput > fOutput)
            {
                fMinOutput = fOutput;
            }
            if (fMaxOutput < fOutput)
            {
                fMaxOutput = fOutput;
            }
        }

        position = new Vector2(250, 70) + currentInspacetorRect.position;
        size     = new Vector2(GRAPH_WIDTH, GRAPH_HEIGHT);

        //for each input of the responsecurve, paint a BOX of output height
        for (int i = 0; i < myTarget.GetCurveDefinitionSize(); i++)
        {
            float fInput  = myTarget.GetCurveDefinitionInputAt(i);
            float fOutput = myTarget.GetValue(fInput);

            fInput  /= (fMaxInput == fMinInput) ? 1 : (fMaxInput - fMinInput);     // normalize input to 0-1
            fOutput /= (fMaxOutput == fMinOutput) ? 1 : (fMaxOutput - fMinOutput); // normalize output to 0-1
            //paint
            GUI.Box(new Rect(position.x + size.x * fLastStepInput,
                             position.y,
                             size.x * (fInput - fLastStepInput),
                             -size.y * (fOutput)),
                    "");
            fLastStepInput = fInput;
        }

        EditorGUILayout.EndVertical();
    }
예제 #9
0
 public ResponseCurve(ResponseCurve responseCurve)
 {
     curveType   = responseCurve.curveType;
     slope       = responseCurve.slope;
     exponential = responseCurve.exponential;
     xShift      = responseCurve.xShift;
     yShift      = responseCurve.yShift;
 }
예제 #10
0
        public static ResponseCurve ResponseCurveField(Rect position, ResponseCurve curve)
        {
            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            ResponseCurveFieldState state = (ResponseCurveFieldState)GUIUtility.GetStateObject(
                typeof(ResponseCurveFieldState),
                controlID);

            Rect left = new Rect(position);

            left.width *= 0.5f;
            Rect right = new Rect(position);

            right.x     += left.width;
            right.width -= left.width;

            if (Event.current.type == EventType.Repaint)
            {
                curve.DrawGraph(state.texture, right.width, right.height);
            }

            EditorGUI.DrawPreviewTexture(right, state.texture);

            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 80f;

            s_guiRect.SetRect(left);
            curve.curveType = (ResponseCurveType)EditorGUI.EnumPopup(s_guiRect.GetFieldRect(), "Curve Type", curve.curveType);
            curve.slope     = EditorGUI.FloatField(s_guiRect.GetFieldRect(), "Slope", curve.slope);
            curve.exp       = EditorGUI.FloatField(s_guiRect.GetFieldRect(), "Exp", curve.exp);
            curve.vShift    = EditorGUI.FloatField(s_guiRect.GetFieldRect(), "V Shift", curve.vShift);
            curve.hShift    = EditorGUI.FloatField(s_guiRect.GetFieldRect(), "H Shift", curve.hShift);
            curve.threshold = EditorGUI.FloatField(s_guiRect.GetFieldRect(), "Threshold", curve.threshold);

            Rect lineRect = s_guiRect.GetFieldRect();

            Rect toggleRect = new Rect(lineRect)
            {
                width = EditorGUIUtility.labelWidth + 16f
            };

            Rect selectRect = new Rect(lineRect)
            {
                x     = lineRect.x + toggleRect.width,
                width = lineRect.width - toggleRect.width
            };

            curve.invert = EditorGUI.Toggle(toggleRect, "Invert", curve.invert);

            int idx = EditorGUI.Popup(selectRect, 0, PresetCurveNames);

            curve = ApplyResponseCurvePreset(PresetCurveNames[idx], curve);

            EditorGUIUtility.labelWidth = oldWidth;
            return(curve);
        }
예제 #11
0
    public object Clone()
    {
        ResponseCurve curve = new ResponseCurve();

        curve.slope     = slope;
        curve.exp       = exp;
        curve.vShift    = vShift;
        curve.hShift    = hShift;
        curve.threshold = threshold;
        curve.curveType = curveType;
        return(curve);
    }
예제 #12
0
        public void Apply(ResponseCurve outCurve)
        {
            if (SuggestedPresetList.Items.Count <= 0 || SuggestedPresetList.SelectedItems.Count <= 0)
            {
                return;
            }

            var curve = SuggestedPresetList.SelectedItems[0].Tag as ResponseCurve;

            outCurve.Type     = curve.Type;
            outCurve.Exponent = curve.Exponent;
            outCurve.Slope    = curve.Slope;
            outCurve.XShift   = curve.XShift;
            outCurve.YShift   = curve.YShift;
        }
예제 #13
0
        private void DrawHeaderBox(ReflectedProperty property, bool withPreview, ResponseCurve curve)
        {
            Rect headerRect  = guiRect.GetFieldRect(2);
            Rect foldoutRect = new Rect(headerRect)
            {
                y     = headerRect.y + 8f,
                width = 20f
            };

            Rect texRect = new Rect(headerRect)
            {
                x     = headerRect.x + 20,
                width = 64f
            };

            Rect selectRect = new Rect(headerRect)
            {
                x      = texRect.x + texRect.width + 8,
                y      = texRect.y + 8,
                height = EditorGUIUtility.singleLineHeight,
                width  = headerRect.width - texRect.width - foldoutRect.width - 8f
            };

            property.IsExpanded = EditorGUI.Foldout(foldoutRect, property.IsExpanded, string.Empty);

            if (withPreview)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    curve.DrawGraph(graphTexture, 64, 32);
                }

                if (Event.current.type == EventType.MouseDown)
                {
                    if (texRect.Contains(Event.current.mousePosition))
                    {
                        if (property.Value != null)
                        {
                            property.IsExpanded = true;
                            Event.current.Use();
                        }
                    }
                }

                EditorGUI.DrawPreviewTexture(texRect, graphTexture);
            }
            DrawTypeSelect(selectRect, property);
        }
예제 #14
0
        public void ExceptionTest()
        {
            ResponseCurve responseCurve = (new GameObject()).AddComponent <ResponseCurve>();

            responseCurve.Initialize(new float[] { 0, 3, 4, 7, 10 },
                                     new float[] { 0, 3, 1, -4, 3 });

            Assert.AreEqual(responseCurve.GetValue(1.5f), 1.5f);
            Assert.AreEqual(responseCurve.GetValue(3.0f), 3.0f);
            Assert.AreEqual(responseCurve.GetValue(0.0f), 0.0f);
            Assert.AreEqual(responseCurve.GetValue(10.0f), 3.0f);
            Assert.AreEqual(responseCurve.GetValue(-3.0f), 0.0f);
            Assert.AreEqual(responseCurve.GetValue(26.0f), 3.0f);
            Assert.AreEqual(responseCurve.GetValue(3.7f), 3 + (1 - 3) * (3.7f - 3) / (4 - 3));
            Assert.AreEqual(responseCurve.GetValue(8.5f), -0.5f);
            Assert.Pass();
        }
 protected override void OnUpdate()
 {
     //>> Calculate scores
     // TODO: To emplement the curves to the scorer of each action
     Entities.ForEach((ref EatScorer eatScore,
                       in Hungriness hunger,
                       in Decision decision) =>
     {
         if (decision.action == ActionType.Eat)
         {
             // once it starts to eat, it will not stop until it's full
             eatScore.score = hunger.value <= float.Epsilon ? 0f : 1f;
         }
         else
         {
             var input      = math.clamp(hunger.value * 0.01f, 0f, 1f);
             eatScore.score = ResponseCurve.Exponentional(input, 2f);
         }
     }).ScheduleParallel();
예제 #16
0
    public static float Evaluate(float input, ResponseCurve responseCurve)
    {
        float score = 0;

        switch (responseCurve.curveType)
        {
        case CurveType.Linear:
            score = CalculateLinear(input, responseCurve.slope, responseCurve.exponential, responseCurve.xShift, responseCurve.yShift);
            break;

        case CurveType.Sin:
            score = CalculateSin(input, responseCurve.slope, responseCurve.exponential, responseCurve.xShift, responseCurve.yShift);
            break;

        case CurveType.Binary:
            score = CalculateBinary(input, responseCurve.slope, responseCurve.xShift, responseCurve.yShift);
            break;

        default:
            break;
        }
        return(Mathf.Clamp(score, 0, 1));
    }
예제 #17
0
    static ResponseCurve[] GetCurvesFromSelection()
    {
        ArrayList curves = new ArrayList();

        if (Selection.activeTransform == null)
        {
            return(new ResponseCurve[0]);
        }

        foreach (MonoBehaviour behaviour in Selection.activeTransform.GetComponents(typeof(MonoBehaviour)))
        {
            FieldInfo[] myFieldInfo = behaviour.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            for (int i = 0; i < myFieldInfo.Length; i++)
            {
                if (myFieldInfo[i].FieldType == typeof(AnimationCurve))
                {
                    object curve = myFieldInfo[i].GetValue(behaviour);
                    if (curve != null)
                    {
                        ResponseCurve r = new ResponseCurve();
                        r.field     = myFieldInfo[i];
                        r.behaviour = behaviour;
                        curves.Add(r);
                    }
                }
            }
        }

        if (curves.Count != 0)
        {
            return(curves.ToArray(typeof(ResponseCurve)) as ResponseCurve[]);
        }
        else
        {
            return(new ResponseCurve[0]);
        }
    }
예제 #18
0
    private void RenderCurve(SerializedPropertyX curveProperty, ConsiderationRenderData data)
    {
        ResponseCurve curve         = curveProperty.GetValue <ResponseCurve>();
        bool          updateTexture = false;
        Texture2D     graphTexture  = data.graphTexture;

        if (graphTexture == null)
        {
            data.graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true);
        }
        EditorGUILayout.BeginHorizontal();
        data.isCurveShown = EditorGUILayout.Foldout(data.isCurveShown, "Curve(" + curve.curveType.ToString() + ")");
        if (!data.isCurveShown)
        {
            if (graphTexture.width != 64)
            {
                graphTexture.Resize(64, 32);

                Rect rect = new Rect()
                {
                    x      = 0,
                    y      = 0,
                    width  = graphTexture.width,
                    height = graphTexture.height
                };
                GraphHelper.DrawGraphLines(rect, graphTexture, (float input) => {
                    return(curve.Evaluate(input));
                });
                graphTexture.FlipVertically();
                graphTexture.Apply(true);
            }
            GUILayout.FlexibleSpace();
            GUIContent content = new GUIContent();
            content.text  = curve.DisplayString;
            content.image = graphTexture;
            GUIStyle style = new GUIStyle(GUI.skin.box);
            style.alignment = TextAnchor.MiddleLeft;
            GUILayout.Box(content, style);
        }

        EditorGUILayout.EndHorizontal();

        if (!data.isCurveShown)
        {
            return;
        }

        DrawerUtil.PushIndentLevel(1);

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUI.BeginChangeCheck();
            GUILayout.BeginVertical(GUILayout.MaxWidth(400f));
            curve.curveType = (ResponseCurveType)EditorGUILayout.EnumPopup("Curve Type", curve.curveType);
            curve.slope     = EditorGUILayout.FloatField("Slope", curve.slope);
            curve.exp       = EditorGUILayout.FloatField("Exp", curve.exp);
            curve.vShift    = EditorGUILayout.FloatField("Vertical Shift", curve.vShift);
            curve.hShift    = EditorGUILayout.FloatField("Horizontal Shift", curve.hShift);
            curve.threshold = EditorGUILayout.FloatField("Threshold", curve.threshold);
            curve.invert    = EditorGUILayout.Toggle(new GUIContent("Inverted"), curve.invert);
            GUILayout.BeginHorizontal();
            GUILayout.Space(EditorGUIUtility.labelWidth);
            if (GUILayout.Button("Reset"))
            {
                curve.Reset();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            updateTexture = EditorGUI.EndChangeCheck();
        }
        //draw the graph
        {
            if (updateTexture || graphTexture.width != 512)
            {
                curveProperty.Update();
                graphTexture.Resize(512, (int)(8.75f * EditorGUIUtility.singleLineHeight));
                Rect rect = new Rect()
                {
                    x      = 0,
                    y      = 0,
                    width  = graphTexture.width,
                    height = graphTexture.height
                };
                GraphHelper.DrawGraphLines(rect, graphTexture, (float input) => {
                    return(curve.Evaluate(input));
                });
                graphTexture.FlipVertically();
                graphTexture.Apply(true);
            }
            DrawerUtil.DrawLayoutTexture(graphTexture);
        }

        EditorGUILayout.EndHorizontal();
        DrawerUtil.PopIndentLevel();
    }
예제 #19
0
    public ResponseCurveEditor(UtilityAIConsiderationEditor utilityAIConsiderationEditor, ResponseCurve responseCurve)
    {
        this.utilityAIConsiderationEditor = utilityAIConsiderationEditor;
        this.responseCurve = responseCurve;

        VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/UtilityAI/Scripts/Editor/Response Curve Editor/ResponseCurveEditor.uxml");

        visualTree.CloneTree(this);

        StyleSheet stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/UtilityAI/Scripts/Editor/Response Curve Editor/ResponseCurveEditor.uss");

        this.styleSheets.Add(stylesheet);

        this.AddToClassList("responseCurveEditor");

        EnumField curveTypeField = this.Query <EnumField>("curveType").First();

        curveTypeField.Init(CurveType.Linear);
        curveTypeField.value = responseCurve.curveType;
        curveTypeField.RegisterCallback <ChangeEvent <Enum> >(
            e =>
        {
            responseCurve.curveType = (CurveType)e.newValue;
            utilityAIConsiderationEditor.UpdateResponseCurve();
        }
            );

        FloatField xShiftField = this.Query <FloatField>("xShift").First();

        xShiftField.value = responseCurve.xShift;
        xShiftField.RegisterCallback <ChangeEvent <float> >(
            e =>
        {
            responseCurve.xShift = (float)e.newValue;
            utilityAIConsiderationEditor.UpdateResponseCurve();
        }
            );

        FloatField yShiftField = this.Query <FloatField>("yShift").First();

        yShiftField.value = responseCurve.yShift;
        yShiftField.RegisterCallback <ChangeEvent <float> >(
            e =>
        {
            responseCurve.yShift = (float)e.newValue;
            utilityAIConsiderationEditor.UpdateResponseCurve();
        }
            );

        FloatField slopeField = this.Query <FloatField>("slope").First();

        slopeField.value = responseCurve.slope;
        slopeField.RegisterCallback <ChangeEvent <float> >(
            e =>
        {
            responseCurve.slope = (float)e.newValue;
            utilityAIConsiderationEditor.UpdateResponseCurve();
        }
            );

        FloatField exponentialField = this.Query <FloatField>("exponential").First();

        exponentialField.value = responseCurve.exponential;
        exponentialField.RegisterCallback <ChangeEvent <float> >(
            e =>
        {
            responseCurve.exponential = (float)e.newValue;
            utilityAIConsiderationEditor.UpdateResponseCurve();
        }
            );

        Box box = new Box()
        {
            style =
            {
                flexGrow     =   1,
                marginTop    =   5,
                marginBottom =   5,
                marginLeft   =   5,
                marginRight  =   5,
                height       = 300,
            }
        };

        this.Add(box);

        VisualElement meshContainer = new VisualElement()
        {
            style = { flexGrow = 1, }
        };

        box.Add(meshContainer);
        meshContainer.generateVisualContent += DrawGraph;
    }
예제 #20
0
 internal void AttachCurve(ResponseCurve curve, Project project)
 {
     ResponseCurveEditor.AttachCurve(curve, project);
 }
 public static void Open(ResponseCurve curve)
 {
     _currentCurve = curve;
     ShowWindow();
 }
예제 #22
0
    void DrawGraph(MeshGenerationContext context)
    {
        float          step   = 1 / context.visualElement.contentRect.width;
        List <Vector3> points = new List <Vector3>();

        for (float i = 0; i <= 1; i += step)
        {
            points.Add(new Vector3(i, ResponseCurve.Evaluate(i, responseCurve), Vertex.nearZ));
        }
        float thickness = 2f;
        Color color     = Color.red;

        List <Vertex> vertices = new List <Vertex>();
        List <ushort> indices  = new List <ushort>();

        for (int i = 0; i < points.Count - 1; i++)
        {
            var pointA = points[i];
            var pointB = points[i + 1];

            pointA.x = pointA.x * context.visualElement.contentRect.width;
            pointA.y = context.visualElement.contentRect.height - pointA.y * context.visualElement.contentRect.height;

            pointB.x = pointB.x * context.visualElement.contentRect.width;
            pointB.y = context.visualElement.contentRect.height - pointB.y * context.visualElement.contentRect.height;

            float angle   = Mathf.Atan2(pointB.y - pointA.y, pointB.x - pointA.x);
            float offsetX = thickness / 2 * Mathf.Sin(angle);
            float offsetY = thickness / 2 * Mathf.Cos(angle);

            vertices.Add(new Vertex()
            {
                position = new Vector3(pointA.x + offsetX, pointA.y - offsetY, Vertex.nearZ),
                tint     = color
            });
            vertices.Add(new Vertex()
            {
                position = new Vector3(pointB.x + offsetX, pointB.y - offsetY, Vertex.nearZ),
                tint     = color
            });
            vertices.Add(new Vertex()
            {
                position = new Vector3(pointB.x - offsetX, pointB.y + offsetY, Vertex.nearZ),
                tint     = color
            });
            vertices.Add(new Vertex()
            {
                position = new Vector3(pointB.x - offsetX, pointB.y + offsetY, Vertex.nearZ),
                tint     = color
            });
            vertices.Add(new Vertex()
            {
                position = new Vector3(pointA.x - offsetX, pointA.y + offsetY, Vertex.nearZ),
                tint     = color
            });
            vertices.Add(new Vertex()
            {
                position = new Vector3(pointA.x + offsetX, pointA.y - offsetY, Vertex.nearZ),
                tint     = color
            });

            ushort indexOffset(int value) => (ushort)(value + (i * 6));

            indices.Add(indexOffset(0));
            indices.Add(indexOffset(1));
            indices.Add(indexOffset(2));
            indices.Add(indexOffset(3));
            indices.Add(indexOffset(4));
            indices.Add(indexOffset(5));
        }

        var mesh = context.Allocate(vertices.Count, indices.Count);

        mesh.SetAllVertices(vertices.ToArray());
        mesh.SetAllIndices(indices.ToArray());
    }
예제 #23
0
 public UtilityAIConsideration()
 {
     name          = "New Utility AI Consideration";
     responseCurve = new ResponseCurve(CurveType.Linear, 1, 1, 0, 0);
 }
예제 #24
0
        private void RenderCurve()
        {
            bool updateTexture;

            if (graphTexture == null)
            {
                graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true);
            }

            if (curve == null)
            {
                curve = new ResponseCurve();
            }

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.EndHorizontal();

            DrawerUtil.PushIndentLevel(1);

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUI.BeginChangeCheck();
                GUILayout.BeginVertical(GUILayout.MaxWidth(400f));
                curve.curveType = (ResponseCurveType)EditorGUILayout.EnumPopup("Curve Type", curve.curveType);
                curve.slope     = EditorGUILayout.FloatField("Slope", curve.slope);
                curve.exp       = EditorGUILayout.FloatField("Exp", curve.exp);
                curve.vShift    = EditorGUILayout.FloatField("Vertical Shift", curve.vShift);
                curve.hShift    = EditorGUILayout.FloatField("Horizontal Shift", curve.hShift);
                curve.threshold = EditorGUILayout.FloatField("Threshold", curve.threshold);
                curve.invert    = EditorGUILayout.Toggle(new GUIContent("Inverted"), curve.invert);
                GUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUIUtility.labelWidth);
                if (GUILayout.Button("Reset"))
                {
                    curve.Reset();
                }

                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
                updateTexture = EditorGUI.EndChangeCheck();
            }
            //draw the graph
            {
                if (updateTexture || graphTexture.width != 512)
                {
                    graphTexture.Resize(512, (int)(8.75f * EditorGUIUtility.singleLineHeight));
                    Rect rect = new Rect()
                    {
                        x      = 0,
                        y      = 0,
                        width  = graphTexture.width,
                        height = graphTexture.height
                    };
                    GraphHelper.DrawGraphLines(rect, graphTexture, (float input) => {
                        return(curve.Evaluate(input));
                    });
                    graphTexture.FlipVertically();
                    graphTexture.Apply(true);
                }

                DrawerUtil.DrawLayoutTexture(graphTexture);
            }

            EditorGUILayout.EndHorizontal();
            DrawerUtil.PopIndentLevel();
        }
예제 #25
0
 public float CalculateScore(float input)
 {
     return(ResponseCurve.Evaluate(input, responseCurve));
 }
예제 #26
0
 public object Clone() {
     ResponseCurve curve = new ResponseCurve();
     curve.slope = slope;
     curve.exp = exp;
     curve.vShift = vShift;
     curve.hShift = hShift;
     curve.threshold = threshold;
     curve.curveType = curveType;
     return curve;
 }
예제 #27
0
        public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null)
        {
            guiRect.SetRect(position);
            if (style == null)
            {
                style = new GUIStyle(GUI.skin.box);
            }

            if (graphTexture == null)
            {
                graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true);
            }

            curve = (ResponseCurve)property.Value ?? new ResponseCurve();

            if (property.IsExpanded)
            {
                EditorGUIX.Foldout(guiRect, property);
            }

            if (!property.IsExpanded)
            {
                DrawGraph(64, 32);
                GUIContent content = EditorGUIX.TempLabel(curve.ShortDisplayString);
                content.image   = graphTexture;
                style.alignment = TextAnchor.MiddleLeft;
                GUI.Box(guiRect.GetFieldRect(2), content, style);
                content.image = null;
                if (Event.current.type == EventType.MouseDown)
                {
                    if (position.Contains(Event.current.mousePosition))
                    {
                        property.IsExpanded = true;
                        Event.current.Use();
                    }
                }
                return;
            }

            GUIRect[] splits = guiRect.SplitHorizontal(0.5f);
            GUIRect   left   = splits[0];
            GUIRect   right  = splits[1];

            DrawGraph(right.GetRect().width, right.GetRect().height);

            GUIContent graphContent = EditorGUIX.TempLabel(string.Empty);

            graphContent.image = graphTexture;
            GUI.Box(right.GetRect(), graphContent, style);
            graphContent.image = null;
            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 100;

            EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("curveType"));
            EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("slope"));
            EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("exp"));
            EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("vShift"));
            EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("hShift"));
            EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("threshold"));

            Rect lineRect   = left.GetFieldRect();
            Rect toggleRect = new Rect(lineRect)
            {
                width = EditorGUIUtility.labelWidth + 16f
            };
            Rect selectRect = new Rect(lineRect)
            {
                x     = lineRect.x + toggleRect.width,
                width = lineRect.width - toggleRect.width
            };

            EditorGUIX.PropertyField(toggleRect, property.FindProperty("invert"));

            int idx = EditorGUI.Popup(selectRect, 0, presetCurveNames);

            property.Value = GetPreset(presetCurveNames[idx], curve);

            EditorGUIUtility.labelWidth = oldWidth;
            property.ApplyChanges();
        }
예제 #28
0
    // --------------------------------------------------------------------------------

    public void OnEnable()
    {
        m_responseCurve = target as ResponseCurve;
        m_material      = new Material(Shader.Find("Hidden/Internal-Colored"));
    }
예제 #29
0
 private void DrawCollapsed(ReflectedProperty property, ResponseCurve curve)
 {
     DrawHeaderBox(property, true, curve);
     EditorGUIX.DrawProperties(guiRect.GetRect(), property, new[] { "curve" });
 }
예제 #30
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (graphTexture == null)
            {
                graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true);
            }

            curve = SerializedPropertyUtil.GetTargetObjectOfProperty(property) as ResponseCurve ?? new ResponseCurve();
            GUIRect rect = new GUIRect(position);

            isCurveShown = curve.__editorOnlyFoldout__ = EditorGUI.Foldout(rect.GetFieldRect(), curve.__editorOnlyFoldout__, label.text);

            GUIStyle style = new GUIStyle(GUI.skin.box);

            if (!isCurveShown)
            {
                DrawGraph(64, 32);
                GUIContent content = new GUIContent();
                content.text    = curve.DisplayString;
                content.image   = graphTexture;
                style.alignment = TextAnchor.MiddleLeft;
                GUI.Box(rect.GetFieldRect(2), content, style);
                return;
            }

            GUIRect[] splits = rect.SplitHorizontal(0.5f);
            GUIRect   left   = splits[0];
            GUIRect   right  = splits[1];

            DrawGraph(right.GetRect().width, right.GetRect().height);

            GUIContent graphContent = new GUIContent();

            graphContent.image = graphTexture;
            GUI.Box(right.GetRect(), graphContent, style);
            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 100;

            DrawerUtil.PushIndentLevel(1);
            EditorGUI.BeginChangeCheck();
            {
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("curveType"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("slope"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("exp"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("vShift"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("hShift"));
                EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("threshold"));
                GUIRect   lineRect      = new GUIRect(left.GetFieldRect());
                GUIRect[] lineRectParts = lineRect.SplitHorizontal(0.5f);
                EditorGUI.PropertyField(lineRectParts[0].GetRect(), property.FindPropertyRelative("invert"));


                if (GUI.Button(lineRectParts[1].GetRect(), "Reset Curve"))
                {
                    property.FindPropertyRelative("curveType").intValue   = (int)ResponseCurveType.Polynomial;
                    property.FindPropertyRelative("slope").floatValue     = 1f;
                    property.FindPropertyRelative("exp").floatValue       = 1f;
                    property.FindPropertyRelative("vShift").floatValue    = 0f;
                    property.FindPropertyRelative("hShift").floatValue    = 0f;
                    property.FindPropertyRelative("threshold").floatValue = 0f;
                    property.FindPropertyRelative("invert").boolValue     = false;
                }
            }
            DrawerUtil.PopIndentLevel();
            EditorGUIUtility.labelWidth = oldWidth;
            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.ApplyModifiedProperties();
            }
        }
예제 #31
0
 public UtilityAIConsideration(UtilityAIConsideration consideration)
 {
     name          = consideration.name;
     enabled       = consideration.enabled;
     responseCurve = new ResponseCurve(consideration.responseCurve);
 }