Example #1
0
    //-----------------------------------------------------------------------------------------------
    public override void Run()
    {
        OperatorParam influenceMapParamName = FindParamWithName("Influence");

        // Can't exactly move if we don't have a goal
        if (influenceMapParamName == null)
        {
            return;
        }

        string[] mapIdentifiers = influenceMapParamName.Value.Split('_');

        // Determine map type
        InfluenceSystem   influenceSys = InfluenceSystem.GetInstance();
        InfluenceMapPoint mapPoint;

        if (mapIdentifiers[0].Equals("Base", StringComparison.CurrentCultureIgnoreCase))
        {
            WorkingMap queryMap = new WorkingMap();
            queryMap.AddMap(influenceSys.GetInfluenceMapByIDWithTag(mapIdentifiers[1], mapIdentifiers[2]));
            queryMap.Normalize();
            mapPoint = queryMap.GetPointOfHighestInfluence();
        }
        else if (mapIdentifiers[0].Equals("Formula", StringComparison.CurrentCultureIgnoreCase))
        {
            MapFormula formulaToUse = influenceSys.GetMapFormulaByID(mapIdentifiers[1]);
            WorkingMap queryMap     = formulaToUse.ConstructMapFromFormula();
            mapPoint = queryMap.GetPointOfHighestInfluence();
        }
        else
        {
            throw new ArgumentException("Invalid name for influence map in move to operator!");
        }

        InfluenceObjectWorldPoint worldPoint = influenceSys.ConvertMapPosToWorldPos(mapPoint);
        Vector2 newLocation = new Vector2(worldPoint.x, worldPoint.y);

        AgentToOperateOn.transform.position = newLocation;

        InfluenceGameManager influenceManager = GameObject.FindObjectOfType <InfluenceGameManager>();

        influenceManager.UpdateInfluenceSystem();
    }
    //-----------------------------------------------------------------------------------------------
    public void OnSceneGUI(SceneView sceneView)
    {
        if (!m_showHighestInfluencePoint)
        {
            return;
        }

        // Save previous state
        Color oldColor = Handles.color;

        foreach (MapSelection selection in m_mapSelections)
        {
            if ((selection.m_isHidden) ||
                (selection.m_activeMap == null))
            {
                continue;
            }

            Color mapColor   = selection.m_renderColor;
            Color outerColor = new Color(mapColor.r, mapColor.g, mapColor.b, 1f);
            Color innerColor = new Color(mapColor.r, mapColor.g, mapColor.b, .3f);

            InfluenceMapPoint         highestPoint = selection.m_activeMap.GetPointOfHighestInfluence();
            InfluenceObjectWorldPoint worldPos     = m_influenceSystemRef.ConvertMapPosToWorldPos(highestPoint);
            Vector3 unityWorldPos = new Vector3(worldPos.x, worldPos.y, 0f);

            // Draw point
            Handles.color = innerColor;
            Handles.DrawSolidDisc(unityWorldPos, new Vector3(0f, 0f, 1f), .3f);

            Handles.color = outerColor;
            Handles.DrawWireDisc(unityWorldPos, new Vector3(0f, 0f, 1f), .3f);
        }

        // Restore old state
        Handles.color = oldColor;
    }