private void OnSceneGUI(SceneView scene)
 {
     
     UpdateOther(scene);
     UpdateSetCam(scene);                
     timer.Update();
 }
示例#2
0
	static void OnScene(SceneView sceneview)
	{
		var targets = GameObject.FindObjectsOfType<SimpleCCD>();

		foreach (var target in targets)
		{
			foreach (var node in target.angleLimits)
			{
				if (node.Transform == null)
					continue;

				Transform transform = node.Transform;
				Vector3 position = transform.position;

				float handleSize = HandleUtility.GetHandleSize(position);
				float discSize = handleSize * gizmoSize;


				float parentRotation = transform.parent ? transform.parent.eulerAngles.z : 0;
				Vector3 min = Quaternion.Euler(0, 0, node.min + parentRotation)*Vector3.down;
				Vector3 max = Quaternion.Euler(0, 0, node.max + parentRotation)*Vector3.down;

				Handles.color = new Color(0, 1, 0, 0.1f);
				Handles.DrawWireDisc(position, Vector3.back, discSize);
				Handles.DrawSolidArc(position, Vector3.forward, min, node.max - node.min, discSize);

				Handles.color = Color.green;
				Handles.DrawLine(position, position + min * discSize);
				Handles.DrawLine(position, position + max*discSize);

				Vector3 toChild = FindChildNode(transform, target.endTransform).position - position;
				Handles.DrawLine(position, position + toChild);
			}
		}
	}
    public override void OnSceneGui(SceneView sc)
    {
        #if UNITY_EDITOR
        bool spa = Event.current.keyCode == KeyCode.F1;
        bool bag = Event.current.keyCode == KeyCode.F2;
        if (Event.current.type == EventType.keyDown && (spa || bag))
        {
            RaycastHit h;
            var spw = GameObject.Find("dmSpawns");
            if (spw == null)
                spw = new GameObject("dmSpawns");

            Vector2 mousePosition = Event.current.mousePosition;
            mousePosition.y = Screen.height - mousePosition.y - 40;

            if (Physics.Raycast(sc.camera.ScreenPointToRay(mousePosition), out h))
            {
                GameObject a;
                if (bag)
                    a = (GameObject)PrefabUtility.InstantiatePrefab(resEditor.bag);
                else
                    a = new GameObject("Spawn");
                Undo.RegisterCreatedObjectUndo(a, "a");
                a.transform.position = h.point + Vector3.up * 1;
                a.transform.parent = spw.transform;
                if (spa)
                    a.AddComponent<Spawn>();
            }
        }
        #endif
    }
    void OnSceneGUI(SceneView sceneView)
    {
        Event e = Event.current;

        if (e.type == EventType.KeyDown)
        {
            switch (e.keyCode)
            {
                case KeyCode.PageUp:
                    selectedLayer = Wrap(--selectedLayer, layerNames.Length);
                    Selection.activeGameObject = tilemapGos[selectedLayer];
                    break;

                case KeyCode.PageDown:
                    selectedLayer = Wrap(++selectedLayer, layerNames.Length);
                    Selection.activeGameObject = tilemapGos[selectedLayer];
                    break;

                default:
                    break;
            }
            e.Use();
        }

        Handles.BeginGUI();

        selectedLayer = GUI.SelectionGrid(new Rect(0, 32, 128, 64), selectedLayer, layerNames, 1);

        if (fadeOtherLayers)
        {
            SetTileMapLayerColors();
        }

        Handles.EndGUI();
    }
 private void OnSceneGui(SceneView s)
 {
     if (lastObj != null)
     {
         lastObj.OnSceneGui(s);
     }
 }
示例#6
0
	static void OnSceneInteract(SceneView sceneView)
	{
		Event e = Event.current;
		
		if (isActive)
		{
			Vector2 mousePos = Event.current.mousePosition;
			mousePos.y = sceneView.camera.pixelHeight - mousePos.y;
			Vector3 position = sceneView.camera.ScreenPointToRay(mousePos).origin;
			Vector3 roundedPosition = new Vector3(Mathf.Round((position.x / SIZE_X) * SIZE_X), Mathf.Round((position.y / SIZE_Y) * SIZE_Y), 0);
			if (e.type == EventType.MouseDown && e.button == 0)
			{
				if (Selection.activeGameObject && Selection.activeGameObject.tag == "Tile")
					LastTile = Selection.activeGameObject;
				if (LastTile)
				{	
					GameObject tile = Instantiate(LastTile, roundedPosition, Quaternion.identity) as GameObject;
					tile.name = LastTile.name;
				}
			}
			else if (e.type == EventType.MouseDown && e.button == 1)
			{
				GameObject[] tiles = GameObject.FindGameObjectsWithTag("Tile");
				foreach (GameObject tile in tiles)
				{
					if (tile.transform.position == roundedPosition)
						DestroyImmediate(tile);
				}
			}
		}
	}
示例#7
0
    public static void Update(SceneView sv)
    {
        Event e = Event.current;

        if (e == null)
        {
            return;
        }

        if (e.type == EventType.keyDown)
        {
            switch(e.keyCode)
            {
                case KeyCode.L:

                    GrendelEditorPreferences.DrawEditorObjectLabels = !GrendelEditorPreferences.DrawEditorObjectLabels;

                break;

                case KeyCode.End:

                    MoveObjectToGround.Move(Selection.activeGameObject);

                break;
            }
        }
    }
示例#8
0
    void GridUpdate(SceneView sceneView)
    {
        Event e = Event.current;

        Ray r = Camera.current.ScreenPointToRay(new Vector3(e.mousePosition.x, -e.mousePosition.y + Camera.current.pixelHeight));
        Vector3 mousePosition = r.origin;

        if(e.isKey && e.character == 'a') {

            GameObject obj;

            Object prefab = PrefabUtility.GetPrefabParent(Selection.activeObject);

            if (prefab)
            {
                obj = (GameObject)PrefabUtility.InstantiatePrefab(prefab);

                Vector3 closestGridPoint = grid.grid[0,0];
                foreach(Vector3 point in grid.grid)
                {
                    if (Mathf.Abs(Vector3.Distance(point, mousePosition)) < Mathf.Abs(Vector3.Distance(closestGridPoint, mousePosition)))
                        closestGridPoint = point;
                }

                Vector3 alignedWithGrid = closestGridPoint;
                obj.transform.position = alignedWithGrid;
            }

        }
    }
    void GridUpdate(SceneView sceneview)
    {
        e = Event.current;

        //Make sure MapData has been loaded
        _MapData = EditorHelper.CheckMapData(_MapData);

        //If a Grid exists place tiles
        if (EditorHelper.GridExsists())
        {
            if(grid == null)
            {
                grid = GameObject.FindObjectOfType<DrawGrid>();
            }

            if (EditorHelper.InsideGrid(EditorHelper.GetMousePosition(e)))
            {
                //if input is from a mouse and the mouse button was a left click event
                if (e.button == 0 && e.isMouse && e.type == EventType.MouseDown)
                {
                    PaintTile();
                }
            }
        }
    }
示例#10
0
    void SceneGUI(SceneView sceneView)
    {
        Event e = Event.current;

        Handles.BeginGUI();

        switch (uiMode)
        {
            case UIMODE.MODE1:
                {
                    if (GUI.Button(new Rect(10, 10, 100, 50), "to MODE2"))
                        uiMode = UIMODE.MODE2;
                }
                break;
            case UIMODE.MODE2:
                {
                    if (GUI.Button(new Rect(10, 10, 100, 50), "to MODE1"))
                        uiMode = UIMODE.MODE1;

                    if (GUI.Button(new Rect(150, 10, 200, 50), "Show My Window"))
                    {
                        Debug.Log("Hello =====================");
                        isShow = !isShow;
                    }

                    if (isShow)
                        GUILayout.Window(0, new Rect(10, 90, 300, 300), ShowMyWindow, "Unity Objects");
                }
                break;
        }

        Handles.EndGUI();
    }
示例#11
0
 static void OnSceneGUI(SceneView scnView)
 {
     if (_toolbarEnabled)
     {
         GUI.Window(110, new Rect(0,16, 256, _buttonSize), ToolbarWindow,"", GUI.skin.label);
     }
 }
示例#12
0
        /// <summary>
        /// Returns SceneView representation more suitable for ray tracer.
        /// </summary>
        /// <param name="fov">Field of view in degrees.</param>
        /// <param name="aspectRatio">Width / height of the rectangle in space to render.</param>
        /// <returns></returns>
        public SceneView ToSceneView(double fov, double aspectRatio)
        {
            SceneView view = new SceneView();
            view.Origin = this.Origin;

            Vector lookVector = LookAt - Origin;

            double rectWidth = lookVector.Len / (double)60 * fov;
            double rectHeight = rectWidth / aspectRatio;

            // use UP vector to determine left vector
            view.RenderRectTopSide = new Vector(0, 1, 0).Cross(lookVector);
            view.RenderRectTopSide.Normalize();
            view.RenderRectTopSide.Mul(rectWidth);

            // top vector must be perpendicular to lookVector and left vector
            view.RenderRectLeftSide = view.RenderRectTopSide.Cross(lookVector);
            view.RenderRectLeftSide.Normalize();
            view.RenderRectLeftSide.Mul(-rectHeight);

            // render rect centered at LookAt
            view.RenderRectOrigin = LookAt;
            view.RenderRectOrigin -= view.RenderRectLeftSide / 2;
            view.RenderRectOrigin -= view.RenderRectTopSide / 2;

            double test = lookVector.Dot(view.RenderRectLeftSide);
            double test2 = lookVector.Dot(view.RenderRectTopSide);
            Debug.Assert(Math.Abs(test) < Constants.Epsilon && Math.Abs(test2) < Constants.Epsilon,
                "RenderRect not perpendicular to lookVector");

            return view;
        }
 /// <summary>
 /// Create a new point. This will activate drawing experience on the map. To complete it, select location from the map.
 /// </summary>
 /// <param name="sceneView">The <see cref="SceneView"/> that is used for drawing.</param>
 /// <exception cref="TaskCanceledException">If previous task wasn't completed, <see cref="TaskCanceledException"/>
 /// will be thrown. The task is cancelled if <see cref="Cancel"/> method or if any other draw or edit method is called.
 /// </exception>
 /// <returns>Return new <see cref="MapPoint"/> based on the user interactions.</returns>
 public static async Task<MapPoint> CreatePointAsync(SceneView sceneView)
 {
     Initialize();
     var geometry = await SceneDrawHelper.DrawPointAsync(sceneView, _drawTaskTokenSource.Token);
     Cleanup();
     return geometry;
 }
示例#14
0
    void GridUpdate(SceneView sceneview)
    {
        Event e = Event.current;

        Ray r = Camera.current.ScreenPointToRay(new Vector3(e.mousePosition.x, -e.mousePosition.y + Camera.current.pixelHeight));
        Vector3 mousePos = r.origin;

        if (e.isKey && e.character == 'a')
        {
            GameObject obj;
            Object prefab = PrefabUtility.GetPrefabParent(Selection.activeObject);

            if (prefab)
            {
                Undo.IncrementCurrentGroup();
                obj = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
                blocks.Add(obj);
                Vector3 aligned = new Vector3(Mathf.Floor(mousePos.x / grid.width) * grid.width + grid.width / 2.0f,
                                  Mathf.Floor(mousePos.y / grid.height) * grid.height + grid.height / 2.0f, 0.0f);

                int blockOrientation = 0;
                for (int i = blocks.Count - 1; i >= 0; i--)
                {
                    if (blocks[i] == null || blocks[i].transform.position == aligned)
                    {
                        DestroyImmediate(blocks[i]);
                        blocks.RemoveAt(i);
                    }
                    Debug.Log("aligned=" + aligned + " Block Position=" + blocks[i].transform.position);
                }
                obj.transform.position = aligned;
                obj.transform.SetParent(GameObject.Find("Grid").transform);
                if (obj.tag == "Grass")
                {
                    grassBlocks.Add(obj);
                    for (int i = grassBlocks.Count - 1; i >= 0; i--)
                    {
                        blockOrientation = 15;
                        Vector3 up = new Vector3(grassBlocks[i].transform.position.x, grassBlocks[i].transform.position.y + 1.0f, 0.0f);
                        Vector3 down = new Vector3(grassBlocks[i].transform.position.x, grassBlocks[i].transform.position.y - 1.0f, 0.0f);
                        Vector3 left = new Vector3(grassBlocks[i].transform.position.x - 1.0f, grassBlocks[i].transform.position.y, 0.0f);
                        Vector3 right = new Vector3(grassBlocks[i].transform.position.x + 1.0f, grassBlocks[i].transform.position.y, 0.0f);
                        for (int j = grassBlocks.Count - 1; j >= 0; j--)
                        {
                            if (grassBlocks[j].transform.position == up) blockOrientation -= 1;
                            if (grassBlocks[j].transform.position == down) blockOrientation -= 2;
                            if (grassBlocks[j].transform.position == left) blockOrientation -= 4;
                            if (grassBlocks[j].transform.position == right) blockOrientation -= 8;
                            Debug.Log(" Block Orientation=" + blockOrientation);
                        }
                        Debug.Log(" Block sprite=" + i + " grassSprite= " + blockOrientation);
                        Debug.Log(" Blocks=" + grassBlocks.Count + " grass= " + grassSprites.Length);
                        grassBlocks[i].GetComponent<SpriteRenderer>().sprite = grassSprites[blockOrientation];
                    }
                }
                Undo.RegisterCreatedObjectUndo(obj, "Create " + obj.name);
            }
        }
    }
 public void OnSceneGUI(SceneView sceneView)
 {
     // Select objects with right mouse
     if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
     {
         _ctrlKeyFlag = Event.current.control;
         MouseRightClickFlag = true;
         MousePosition = Event.current.mousePosition;
     }
 }
示例#16
0
 public void DrawNode(SceneView view)
 {
     Handles.BeginGUI();
     //GUILayout.BeginArea(new Rect(50, 50, 500, 500));
     view.BeginWindows();
     screenPosition = GUI.Window(0, screenPosition, DrawWindowGUI, name );
     view.EndWindows();
        // GUILayout.EndArea();
     Handles.EndGUI();
 }
示例#17
0
    public static void OnSceneGUI(SceneView sceneview)
    {
        if ((currentSelection== null) || (currentSelectionMesh == null) || (currentSelectionMeshFilter == null) )
            return;

        SetMaterial();

        int ctrlID = GUIUtility.GetControlID (VertexPainterHash , FocusType.Passive);
        Event current = Event.current;

        switch(current.type){
        case EventType.keyUp :
            if ((current.keyCode == KeyCode.Q) && (current.control))
                RenderVertexColors = !RenderVertexColors;
            break;

        case EventType.mouseUp:
            switch (currentMode) {
                case Mode.Painting:

                break;
            }
            break;
        case EventType.mouseDown:

            switch (currentMode) {
                case Mode.Painting:
                    current.Use();
                break;
            }
            break;
        case EventType.mouseDrag:
            switch (currentMode) {
                case Mode.None:

                break;
                case Mode.Painting:
                    EditorUtility.SetDirty(currentSelectionMesh);
                    PaintVertexColors();
                break;
            }
            DrawHandle();
            HandleUtility.Repaint();
            break;
        case EventType.mouseMove:
            HandleUtility.Repaint();
            break;
        case EventType.repaint:
            DrawHandle();
            break;
        case EventType.layout:
            HandleUtility.AddDefaultControl(ctrlID);
            break;
        }
    }
示例#18
0
    /// <summary>
    /// Used for handling keyboard input.
    /// </summary>
    public virtual void Input (SceneView _sceneView) {

        if (settingsObject == null) {

            settingsObject = VMESettingsObject.LoadScriptableObject();

        }

        OnSceneUI(_sceneView);

    }
示例#19
0
    static void OnScene(SceneView sceneView)
    {
        var current = Event.current;
        switch(current.type)
        {
            case EventType.DragPerform:
            {
                break;
            }
            case EventType.DragUpdated:
            {
                break;
            }
            case EventType.DragExited:
            {
                break;
            }
            case EventType.MouseMove:
            {
                break;
            }
            case EventType.MouseDown:
            {
                break;
            }
            case EventType.MouseUp:
            {
                break;
            }
            case EventType.Repaint:
            {
                Vector3 delta = new Vector3(0,0,10.0f);
                LineDrawer.DrawLine(Matrix4x4.identity, Vector3.zero, delta, new Color(1,1,1,0.75f));

                for (int i = 2; i < 20; i++)
                {
                    var pos = new Vector3(i, 0, 0);
                    LineDrawer.DrawDottedLine(Matrix4x4.identity, pos, pos + delta, new Color(1, 1, 1, 0.75f), i);
                }
                break;
            }
            case EventType.Layout:
            {
                break;
            }
            default:
            {
                break;
            }
        }
    }
示例#20
0
 // Update - Scene
 public static void OnSceneGUI(SceneView sceneview)
 {
     if (Event.current.type == EventType.mouseDown)
         button = Event.current.button;
     if (Event.current.type == EventType.mouseUp)
         button = -1;
     if (Event.current.type == EventType.keyDown && Event.current.keyCode == KeyCode.N)
         editing = !editing;
     if (button > -1 && editing)
     {
         editPrefab(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition));
         Event.current.Use();
     }
 }
示例#21
0
 /// <summary>
 /// This is the delegate function given to SceneView.onSceneGUIDelegate
 /// which allows us to draw the grid in the scene view.
 /// </summary>
 /// <param name="sv">
 /// A <see cref="SceneView"/>
 /// </param>
 static void DrawInScene(SceneView sv)
 {
     if (showGridXZ)
     {
         DrawXZGrid();
     }
     if (showGridYX)
     {
         DrawYXGrid();
     }
     if (showGridYZ)
     {
         DrawYZGrid();
     }
 }
示例#22
0
    public override void OnSceneGUI(SceneView scene, ref bool repaint)
    {
        Event e = Event.current;
        if (e.type == EventType.keyDown && e.keyCode == KeyCode.N)
        {
            //Undo.RegisterSceneUndo("rtools");
            Ray r = HandleUtility.GUIPointToWorldRay(e.mousePosition);
            RaycastHit rhit;

            if (Physics.Raycast(r, out rhit, Mathf.Infinity))
            {
                Event.current.Use();
                var n = ((GameObject)Instantiate(NodePrefab)).GetComponent<Node>();
                n.name = Prefix + "Node";
                n.transform.parent = transform;
                n.pos = rhit.point;
                Node lastNode;
                if (Selection.activeGameObject != null && (lastNode = Selection.activeGameObject.GetComponent<Node>()) != null)
                {
                    lastNode.EndNode = false;
                    lastNode.nodes.Add(n);
                    lastNode.transform.LookAt(n.transform);
                    n.EndNode = true;
                    n.rot = lastNode.rot;
                    n.nodes.Add(lastNode);
                    if (lastNode.NextNode != null)
                        lastNode.other.Add(n);
                    else
                        lastNode.NextNode = n;

                    n.PrevNode = lastNode;

                    path = lastNode.parent;
                }
                else
                {
                    path = ((GameObject)Instantiate(PathPrefab)).transform;
                    path.name = Prefix + "Path";
                    path.GetComponent<Path>().StartNode = n;
                    path.position = n.pos;
                    n.StartNode = true;
                    path.parent = this.transform;
                }
                n.parent = path;
                Selection.activeGameObject = n.gameObject;
            }
        }
    }
    void OnSceneGUI(SceneView sceneView)
    {
        var selection = Selection.activeGameObject as GameObject;
        if( selection == null)
            return;

        var cameraTransform =  SceneView.currentDrawingSceneView.camera.transform;
        var rotate = cameraTransform.rotation;
        var cameraPos = cameraTransform.position;

        Color shadowCol = new Color(0.5f, 0, 0, 0.06f);

        foreach( var target in referenceObjectList )
        {
            var obj = SceneObjectUtility.GetGameObject(target.value);
            if( obj == null)
            {
                continue;
            }
            if( obj == Selection.activeGameObject){
                continue;
            }

            var startPosition = selection.transform.position;
            var endPosition = obj.transform.position;

            var size = Vector3.Distance(endPosition, cameraPos) * 0.02f;

            if( startPosition == endPosition )
                continue;

            Handles.color = Color.red;

            var diffPos = startPosition - endPosition;
            var tan = new Vector3(diffPos.y, diffPos.x, diffPos.z);

            var startTan = startPosition;
             var endTan = endPosition  + tan * 0.4f;

            Handles.CircleCap(1, endPosition, rotate, size);

            for(int i=0; i<3; i++)
                Handles.DrawBezier(startPosition, endPosition, startTan, endTan, shadowCol, null, (i + 1) * 5);
            Handles.DrawBezier(startPosition, endPosition, startTan, endTan, Color.red, null, 1);

            Handles.Label(endPosition, obj.name);
        }
    }
		public void OnSceneView(SceneView view) {

			if (this._target == null || this.layout == null) return;

			var pivot = (this._target.transform as RectTransform).pivot;

			if (this.layout.showGrid == true && this.lastPivot == pivot) {

				this.lastPivot = pivot;

				var gridSize = this.layout.gridSize;
				this.ArrangeByGrid(this._target, gridSize);

			}

		}
    private void UpdateOther(SceneView scene)
    {
        bool repaint = false;
        foreach (var a in GameObject.FindGameObjectsWithTag("EditorGUI"))
            a.GetComponent<Base>().OnSceneGUI(scene, ref repaint);
        if (repaint) { Repaint(); }

        var ago = Selection.activeGameObject;
        if (SetPivot)
        {
            var move = oldPivot - ago.transform.position;
            foreach (Transform t in ago.transform)
                t.position += move;
        }
        if (ago != null)
            oldPivot = ago.transform.position;
    }
示例#26
0
    void OnSceneGUI(SceneView sceneView)
    {
        if (placePNode)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                Debug.Log ("Thing 1");

                Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                RaycastHit rayInfo;

                if (Physics.Raycast(worldRay, out rayInfo))
                {
                    GameObject prefab = Resources.LoadAssetAtPath("Assets/Prefabs/PTrack-prefab.prefab", typeof(GameObject)) as GameObject;
                    GameObject[] pNodes = GameObject.FindGameObjectsWithTag("PlayerTrack");
                    GameObject newPNode = Instantiate(prefab) as GameObject;
                    newPNode.name = "PTrack" + (pNodes.Length + 1).ToString();
                    newPNode.tag = "PlayerTrack";
                    newPNode.transform.parent = prefab.transform.parent;

                    newPNode.transform.position = rayInfo.point;

                    if (nextPNode != null)
                    {
                        newPNode.GetComponent<PTrack>().nextPNodes.Add(nextPNode);
                        if (autoNode && prevPNode == null)
                        {
                            nextPNode = newPNode;
                        }
                    }
                    if (prevPNode != null)
                    {
                        prevPNode.GetComponent<PTrack>().nextPNodes.Add(newPNode);
                        if (autoNode && nextPNode == null)
                        {
                            prevPNode = newPNode;
                        }
                    }
                }

                Event.current.Use();

                placePNode = false;
            }
        }
    }
		private void SetSceneView(SceneView sceneView)
		{
			if(this.sceneView != null)
			{
				//Clean up
				this.sceneView.Loaded -= _sceneView_Loaded;
				this.sceneView.Unloaded -= _sceneView_Unloaded;
				Stop();
			}
			this.sceneView = sceneView;
			if(sceneView != null)
			{
				this.sceneView.Loaded += _sceneView_Loaded;
				this.sceneView.Unloaded += _sceneView_Unloaded;
				Start(); //We should only start if already loaded, but no way to detect that currently
			}
		}
示例#28
0
	void StereoUpdate(SceneView sceneview)
	{
		if(cameraTarget==null) return;
		switch (cameraTarget.state) {
			case ThreeDStereoCamera.CameraState.WindowsEditorState:
			{
				cameraTarget.systemCamera.SetActive(true);
				cameraTarget.leftCamera.SetActive(false);
				cameraTarget.rightCamera.SetActive(false);
				cameraTarget.zeroParallaxPlane.SetActive(false);
				
				Camera sc = cameraTarget.systemCamera.GetComponent<Camera>();
				sc.nearClipPlane = cameraTarget.near;
				sc.farClipPlane = cameraTarget.far;
				sc.fieldOfView = cameraTarget.fieldOfView;
				sc.backgroundColor = cameraTarget.cameraBackgroundColor;
				cameraTarget.near = Mathf.Clamp (cameraTarget.near, 0.01f,cameraTarget.far);
				cameraTarget.far = Mathf.Clamp (cameraTarget.far, cameraTarget.near, Mathf.Infinity);
				sc.near = cameraTarget.near;
				sc.far = cameraTarget.far;
				break;
			}
			case ThreeDStereoCamera.CameraState.WindowsStereoState:
			{
				cameraTarget.systemCamera.SetActive(false);
				cameraTarget.leftCamera.SetActive(true);
				cameraTarget.rightCamera.SetActive(true);
				cameraTarget.zeroParallaxPlane.SetActive(true);
				
				computeCameras ();
				computeZeroParallaxPlane ();
				break;
			}
			case ThreeDStereoCamera.CameraState.AndroidRunTimeState:
			{
				cameraTarget.systemCamera.SetActive(false);
				cameraTarget.leftCamera.SetActive(true);
				cameraTarget.rightCamera.SetActive(true);
				cameraTarget.zeroParallaxPlane.SetActive(true);
				
				computeCameras ();
				computeZeroParallaxPlane ();
				break;
			}
		}
	}
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        if (GUILayout.Button("Use current position"))
        {
            SceneViewCameraFollower _target = target as SceneViewCameraFollower;
            sceneViews = SceneView.sceneViews;

            if (_target.sceneViewFollowers.Length > 0)
            {
                sceneView = (SceneView)sceneViews[0];

                _target.sceneViewFollowers[0].positionOffset = sceneView.camera.transform.position - _target.sceneViewFollowers[0].targetTransform.position;
                _target.sceneViewFollowers[0].fixedRotation = sceneView.rotation.eulerAngles;
            }
        }
    }
    public void OnSceneGUI(SceneView sceneView)
    {
        if(enabled)
        {
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));

            if(Selection.activeObject != null)
            {
                if(Selection.activeGameObject != null && Selection.activeTransform == null)
                {
                    newSelectedGameObject = Selection.activeGameObject;
                }

                if(Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    RaycastHit hit;

                    if(Physics.Raycast(ray, out hit))
                    {
                        buildPos = hit.point + offSet;

                        if(Selection.activeGameObject != null && Selection.activeTransform == null)
                        {
                            instantiatePrefab = true;
                        }
                        if(Selection.activeTransform != null)
                        {
                            instantiatePrefab = false;
                        }

                        if(instantiatePrefab == true)
                        {
                            AddSingle(buildPos, hit);
                        }

                        if(instantiatePrefab == false)
                        {
                            WarnUser();
                        }
                    }
                }
            }
        }
    }
示例#31
0
            public static void HandlePreferencesGUI()
            {
                if (!preferencesLoaded)
                {
                    Load();
                }

                EditorGUI.BeginChangeCheck();
                showHierarchyIcons = EditorGUILayout.Toggle(new GUIContent("Show Hierarchy Icons", "Show relevant icons on GameObjects with Spine Components on them. Disable this if you have large, complex scenes."), showHierarchyIcons);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorPrefs.SetBool(SHOW_HIERARCHY_ICONS_KEY, showHierarchyIcons);
                                #if NEWPLAYMODECALLBACKS
                    HierarchyHandler.IconsOnPlaymodeStateChanged(PlayModeStateChange.EnteredEditMode);
                                #else
                    HierarchyHandler.IconsOnPlaymodeStateChanged();
                                #endif
                }

                BoolPrefsField(ref autoReloadSceneSkeletons, AUTO_RELOAD_SCENESKELETONS_KEY, new GUIContent("Auto-reload scene components", "Reloads Skeleton components in the scene whenever their SkeletonDataAsset is modified. This makes it so changes in the SkeletonDataAsset inspector are immediately reflected. This may be slow when your scenes have large numbers of SkeletonRenderers or SkeletonGraphic."));

                EditorGUILayout.Separator();
                EditorGUILayout.LabelField("Auto-Import Settings", EditorStyles.boldLabel);
                {
                    SpineEditorUtilities.FloatPrefsField(ref defaultMix, DEFAULT_MIX_KEY, new GUIContent("Default Mix", "The Default Mix Duration for newly imported SkeletonDataAssets."), min: 0);
                    SpineEditorUtilities.FloatPrefsField(ref defaultScale, DEFAULT_SCALE_KEY, new GUIContent("Default SkeletonData Scale", "The Default skeleton import scale for newly imported SkeletonDataAssets."), min: 0.0000001f);

                    EditorGUI.BeginChangeCheck();
                    var shader = (EditorGUILayout.ObjectField("Default Shader", Shader.Find(defaultShader), typeof(Shader), false) as Shader);
                    defaultShader = shader != null ? shader.name : SpinePreferences.DEFAULT_DEFAULT_SHADER;
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorPrefs.SetString(DEFAULT_SHADER_KEY, defaultShader);
                    }

                    SpineEditorUtilities.BoolPrefsField(ref setTextureImporterSettings, SET_TEXTUREIMPORTER_SETTINGS_KEY, new GUIContent("Apply Atlas Texture Settings", "Apply the recommended settings for Texture Importers."));
                    SpineEditorUtilities.Texture2DPrefsField(ref textureSettingsReference, TEXTURE_SETTINGS_REFERENCE_KEY, new GUIContent("Atlas Texture Reference Settings", "Apply the selected reference texture import settings at newly imported atlas textures. When exporting atlas textures from Spine with \"Premultiply alpha\" enabled (the default), you can leave it at \"PMAPresetTemplate\". If you have disabled \"Premultiply alpha\", set it to \"StraightAlphaPresetTemplate\". You can also create your own reference texture asset and assign it here."));
                    if (string.IsNullOrEmpty(textureSettingsReference))
                    {
                        var pmaTextureSettingsReferenceGUIDS = AssetDatabase.FindAssets("PMAPresetTemplate");
                        if (pmaTextureSettingsReferenceGUIDS.Length > 0)
                        {
                            textureSettingsReference = AssetDatabase.GUIDToAssetPath(pmaTextureSettingsReferenceGUIDS[0]);
                            EditorPrefs.SetString(TEXTURE_SETTINGS_REFERENCE_KEY, textureSettingsReference);
                        }
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Warnings", EditorStyles.boldLabel);
                {
                    SpineEditorUtilities.BoolPrefsField(ref atlasTxtImportWarning, ATLASTXT_WARNING_KEY, new GUIContent("Atlas Extension Warning", "Log a warning and recommendation whenever a `.atlas` file is found."));
                    SpineEditorUtilities.BoolPrefsField(ref textureImporterWarning, TEXTUREIMPORTER_WARNING_KEY, new GUIContent("Texture Settings Warning", "Log a warning and recommendation whenever Texture Import Settings are detected that could lead to undesired effects, e.g. white border artifacts."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Editor Instantiation", EditorStyles.boldLabel);
                {
                    EditorGUI.BeginChangeCheck();
                    defaultZSpacing = EditorGUILayout.Slider("Default Slot Z-Spacing", defaultZSpacing, -0.1f, 0f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorPrefs.SetFloat(DEFAULT_ZSPACING_KEY, defaultZSpacing);
                    }

                    SpineEditorUtilities.BoolPrefsField(ref defaultInstantiateLoop, DEFAULT_INSTANTIATE_LOOP_KEY, new GUIContent("Default Loop", "Spawn Spine GameObjects with loop enabled."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Mecanim Bake Settings", EditorStyles.boldLabel);
                {
                    SpineEditorUtilities.BoolPrefsField(ref mecanimEventIncludeFolderName, MECANIM_EVENT_INCLUDE_FOLDERNAME_KEY, new GUIContent("Include Folder Name in Event", "When enabled, Mecanim events will call methods named 'FolderNameEventName', when disabled it will call 'EventName'."));
                }

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Handles and Gizmos", EditorStyles.boldLabel);
                {
                    EditorGUI.BeginChangeCheck();
                    handleScale = EditorGUILayout.Slider("Editor Bone Scale", handleScale, 0.01f, 2f);
                    handleScale = Mathf.Max(0.01f, handleScale);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EditorPrefs.SetFloat(SCENE_ICONS_SCALE_KEY, handleScale);
                        SceneView.RepaintAll();
                    }
                }

                if (SpineTK2DEditorUtility.IsTK2DInstalled())
                {
                    GUILayout.Space(20);
                    EditorGUILayout.LabelField("3rd Party Settings", EditorStyles.boldLabel);
                    using (new GUILayout.HorizontalScope()) {
                        EditorGUILayout.PrefixLabel("Define TK2D");
                        if (GUILayout.Button("Enable", GUILayout.Width(64)))
                        {
                            SpineTK2DEditorUtility.EnableTK2D();
                        }
                        if (GUILayout.Button("Disable", GUILayout.Width(64)))
                        {
                            SpineTK2DEditorUtility.DisableTK2D();
                        }
                    }
                }

                GUILayout.Space(20);
                EditorGUILayout.LabelField("Timeline Extension", EditorStyles.boldLabel);
                {
                    SpineEditorUtilities.BoolPrefsField(ref timelineUseBlendDuration, TIMELINE_USE_BLEND_DURATION_KEY, new GUIContent("Use Blend Duration", "When enabled, MixDuration will be synced with timeline clip transition duration 'Ease In Duration'."));
                }
            }
        public bool Inspect(ref List <WeatherConfig> configurations)
        {
            bool changed = false;

            bool notInspectingProperty = inspectedProperty == -1;

            "Bleed".edit(60, ref colorBleed.targetValue, 0f, 0.3f).nl(ref changed);

            "Brightness".edit(90, ref brightness.targetValue, 0f, 8f).nl(ref changed);

            shadowDistance.enter_Inspect_AsList(ref inspectedProperty, 3).nl(ref changed);

            bool fog = RenderSettings.fog;

            if (notInspectingProperty && "Fog".toggleIcon(ref fog, true).changes(ref changed))
            {
                RenderSettings.fog = fog;
            }

            if (fog)
            {
                var fogMode = RenderSettings.fogMode;

                if (notInspectingProperty)
                {
                    "Fog Color".edit(60, ref fogColor.targetValue).nl();

                    if ("Fog Mode".editEnum(60, ref fogMode).nl())
                    {
                        RenderSettings.fogMode = fogMode;
                    }
                }

                if (fogMode == FogMode.Linear)
                {
                    fogDistance.enter_Inspect_AsList(ref inspectedProperty, 4).nl(ref changed);
                }
                else
                {
                    fogDensity.enter_Inspect_AsList(ref inspectedProperty, 5).nl(ref changed);
                }
            }

            if (notInspectingProperty)
            {
                "Sky Color".edit(60, ref skyColor.targetValue).nl(ref changed);
            }

            pegi.nl();

            var mgmt = PainterCamera.Inst;

            if (mgmt)
            {
                "Main Directional Light".edit(ref mgmt.mainDirectionalLight).nl(ref changed);

                var l = mgmt.mainDirectionalLight;

                if (l)
                {
                    pegi.nl();
                    mainLightRotation.Nested_Inspect().nl(ref changed);

                    "Light Intensity".edit(ref mainLightIntensity.targetValue).nl(ref changed);
                    "Light Color".edit(ref mainLightColor.targetValue).nl(ref changed);
                }
            }

            var newObj = "Configurations".edit_List(ref configurations, ref changed);

            pegi.nl();

            if (newObj != null)
            {
                ReadCurrentValues();
                newObj.data = Encode().ToString();
                newObj.ActiveConfiguration = newObj;
            }

            if (Application.isPlaying)
            {
                if (ld.MinPortion < 1)
                {
                    "Lerping {0}".F(ld.dominantParameter).write();
                    pegi.FullWindow.DocumentationClickOpen(() => "Each parameter has a transition speed. THis text shows which parameter sets speed for others (the slowest one). " +
                                                           "If Transition is too slow, increase this parameter's speed");
                    pegi.nl();
                }
            }

            if (changed)
            {
                Update();
#if UNITY_EDITOR
                if (Application.isPlaying == false)
                {
                    SceneView.RepaintAll();
                    InternalEditorUtility.RepaintAllViews();
                }
#endif
            }

            if (changed)
            {
                UpdateShader();
            }

            return(changed);
        }
    private void OnBoundsWindowGUI(SceneView sceneView)
    {
        Rect screenRect = new Rect(Screen.width - BoundsWindowSize.x - 25, Screen.height - BoundsWindowSize.y - 20, BoundsWindowSize.x, BoundsWindowSize.y);

        GUILayout.Window(0, screenRect,
                         (int id) =>
        {
            int LabelWidth = 50;

            GUI.enabled = !Application.isPlaying;
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("xMin", GUILayout.Width(LabelWidth));
            bounds.xMin = EditorGUILayout.FloatField(bounds.xMin);
            EditorGUILayout.LabelField("zMin", GUILayout.Width(LabelWidth));
            bounds.yMin = EditorGUILayout.FloatField(bounds.yMin);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("xMax", GUILayout.Width(LabelWidth));
            bounds.xMax = EditorGUILayout.FloatField(bounds.xMax);
            EditorGUILayout.LabelField("zMax", GUILayout.Width(LabelWidth));
            bounds.yMax = EditorGUILayout.FloatField(bounds.yMax);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("xClose", GUILayout.Width(LabelWidth));
            close.x = EditorGUILayout.FloatField(close.x);
            EditorGUILayout.LabelField("zClose", GUILayout.Width(LabelWidth));
            close.y = EditorGUILayout.FloatField(close.y);
            EditorGUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("CloseScale"))
            {
                Vector3[] vertices = navMeshTri.triangulation.vertices;
                if (vertices != null)
                {
                    for (int i = vertices.Length - 1; i >= 0; i--)
                    {
                        Vector3 vertice = vertices[i];
                        if (Mathf.Abs(vertice.x - bounds.xMin) < close.x)
                        {
                            vertice.x = bounds.xMin;
                        }
                        if (Mathf.Abs(vertice.x - bounds.xMax) < close.x)
                        {
                            vertice.x = bounds.xMax;
                        }
                        if (Mathf.Abs(vertice.z - bounds.yMin) < close.y)
                        {
                            vertice.z = bounds.yMin;
                        }
                        if (Mathf.Abs(vertice.z - bounds.yMax) < close.y)
                        {
                            vertice.z = bounds.yMax;
                        }
                        vertices[i] = vertice;
                    }
                }
                navMeshTri.triangulation = navMeshTri.triangulation;
                EditorUtility.SetDirty(navMeshTri);
            }
            GUILayout.EndHorizontal();
            GUI.enabled = true;
        },
                         "Bounds");
    }
示例#34
0
    private void OnSceneGUI(SceneView sceneView)
    {
        //获取TileMap组件
        Tilemap map = FindObjectOfType <Tilemap>();

        if (map == null)
        {
            return;
        }
        //获取鼠标位置,当前是Scene视图坐标
        Vector2 mousePos = Event.current.mousePosition;
        //获取Scene窗体的Camera
        Camera cam = sceneView.camera;
        //Scene窗体中的缩放应当被考虑进去
        float mult = EditorGUIUtility.pixelsPerPoint;

        //将Scene视图的坐标转换成屏幕坐标
        mousePos.y = cam.pixelHeight - mousePos.y * mult;
        mousePos.x = mousePos.x * mult;
        //将屏幕坐标转成世界坐标
        mousePos = sceneView.camera.ScreenToWorldPoint(mousePos);
        Vector3Int vec3 = map.WorldToCell(mousePos);

        string    str         = vec3.ToString();
        int       campID      = -1;
        int       battleUnit  = 0;
        string    terrianName = "";
        bool      opp         = false;
        BattleMap tmb         = FindObjectOfType <BattleMap>();

        if (tmb != null)
        {
            if (tmb.Map != null)
            {
                opp = true;
                int x = tmb.Convert2ArrayIndex(vec3)[0];
                int y = tmb.Convert2ArrayIndex(vec3)[1];
                if (x >= 0 && x < tmb.Map.GetLength(0) && y >= 0 && y < tmb.Map.GetLength(1))
                {
                    campID      = tmb.Map[x, y].CampID;
                    battleUnit  = tmb.Map[x, y].battleUnit;
                    terrianName = tmb.Map[x, y].CurTerrian.name;
                    //  campPlots = tmb.campdi[tmb.Map[x, y].CampID].ownedLands.Count;
                }
            }
        }
        //绘制Label
        Handles.BeginGUI();
        GUIStyle fontStyle = new GUIStyle();

        fontStyle.normal.textColor = Color.green; //设置字体颜色
        fontStyle.fontSize         = 18;          //字体大小
        GUI.Label(new Rect(0f, 120f, 500f, 100f), "当前地块坐标:" + str, fontStyle);
        GUI.Label(new Rect(0f, 150f, 500f, 100f), "当前地块阵营:" + campID.ToString(), fontStyle);
        GUI.Label(new Rect(0f, 180f, 500f, 100f), "当前地块作战单位:" + battleUnit.ToString(), fontStyle);
        GUI.Label(new Rect(0f, 210f, 500f, 100f), "当前地块地形:" + terrianName, fontStyle);
        // GUI.Label(new Rect(0f, 240f, 500f, 100f), "当前阵营地块数量:" + campPlots, fontStyle);
        GUI.Label(new Rect(0f, 270f, 500f, 100f), "地图是否为空:" + opp, fontStyle);
        Handles.EndGUI();

        //刷新界面,保证坐标实时跟随鼠标
        sceneView.Repaint();
        HandleUtility.Repaint();
    }
示例#35
0
        static void DrawSkeletons(SceneView sceneview)
        {
            var gizmoColor = Gizmos.color;

            pyramidMeshRenderer.Clear();
            boxMeshRenderer.Clear();

            for (var i = 0; i < s_BoneRendererComponents.Count; i++)
            {
                var boneRenderer = s_BoneRendererComponents[i];

                if (boneRenderer.bones == null)
                {
                    continue;
                }

                PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
                if (prefabStage != null)
                {
                    StageHandle stageHandle = prefabStage.stageHandle;
                    if (stageHandle.IsValid() && !stageHandle.Contains(boneRenderer.gameObject))
                    {
                        continue;
                    }
                }

                if (boneRenderer.drawBones)
                {
                    var size           = boneRenderer.boneSize * 0.025f;
                    var shape          = boneRenderer.boneShape;
                    var color          = boneRenderer.boneColor;
                    var nubColor       = new Color(color.r, color.g, color.b, color.a);
                    var selectionColor = Color.white;

                    for (var j = 0; j < boneRenderer.bones.Length; j++)
                    {
                        var bone = boneRenderer.bones[j];
                        if (bone.first == null || bone.second == null)
                        {
                            continue;
                        }

                        DoBoneRender(bone.first, bone.second, shape, color, size);
                    }

                    for (var k = 0; k < boneRenderer.tips.Length; k++)
                    {
                        var tip = boneRenderer.tips[k];
                        if (tip == null)
                        {
                            continue;
                        }

                        DoBoneRender(tip, null, shape, color, size);
                    }
                }

                if (boneRenderer.drawTripods)
                {
                    var size = boneRenderer.tripodSize * 0.025f;
                    for (var j = 0; j < boneRenderer.transforms.Length; j++)
                    {
                        var tripodSize = 1f;
                        var transform  = boneRenderer.transforms[j];
                        if (transform == null)
                        {
                            continue;
                        }

                        var position = transform.position;
                        var xAxis    = position + transform.rotation * Vector3.right * size * tripodSize;
                        var yAxis    = position + transform.rotation * Vector3.up * size * tripodSize;
                        var zAxis    = position + transform.rotation * Vector3.forward * size * tripodSize;

                        Handles.color = Color.red;
                        Handles.DrawLine(position, xAxis);
                        Handles.color = Color.green;
                        Handles.DrawLine(position, yAxis);
                        Handles.color = Color.blue;
                        Handles.DrawLine(position, zAxis);
                    }
                }
            }

            pyramidMeshRenderer.Render();
            boxMeshRenderer.Render();

            Gizmos.color = gizmoColor;
        }
    public override void OnInspectorGUI()
    {
        if (handler != null)
        {
            GUILayout.Label("Region Colors");
            GUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            handler.regionOutlineColor = EditorGUILayout.ColorField("Outline", handler.regionOutlineColor);
            handler.regionFillColor    = EditorGUILayout.ColorField("Fill", handler.regionFillColor);
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Add Region", GUILayout.Height(25)))
            {
                Undo.RecordObject(target, "Add Region");

                Ray worldRay = SceneView.lastActiveSceneView.camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 1.0f));
                handler.AddRegion(new Vector2(worldRay.origin.x, worldRay.origin.y));
                selectedIndex = handler.Regions.Count - 1;
                EditorUtility.SetDirty(target);
            }

            EditorGUI.BeginDisabledGroup(handler.Regions.Count > 0 ? false : true);
            if (GUILayout.Button("Validate Regions", GUILayout.Height(25)))
            {
                handler.Validate();
                SceneView.RepaintAll();
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            if (selectedIndex >= 0 && selectedIndex < handler.Regions.Count)
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.IntField("Selected Region Index", selectedIndex);
                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginChangeCheck();
                Vector2 p0 = EditorGUILayout.Vector2Field("Point 0", handler.Regions[selectedIndex].p0);
                Vector2 p1 = EditorGUILayout.Vector2Field("Point 1", handler.Regions[selectedIndex].p1);
                if (EditorGUI.EndChangeCheck())
                {
                    handler.Regions[selectedIndex].p0 = p0;
                    handler.Regions[selectedIndex].p1 = p1;
                    SceneView.RepaintAll();
                }

                if (GUILayout.Button("Remove Region", GUILayout.Height(25)))
                {
                    Undo.RecordObject(target, "Remove Region");
                    handler.RemoveRegion(selectedIndex);
                    selectedIndex--;
                    EditorUtility.SetDirty(target);
                }
            }
        }
    }
示例#37
0
    //called whenever the inspector gui gets rendered
    public override void OnInspectorGUI()
    {
        //this pulls the relative variables from unity runtime and stores them in the object
        targetClass.Update();

        //get waypoint array
        var waypoints = GetWaypointArray();

        //don't draw inspector fields if the path contains less than 2 points
        //(a path with less than 2 points really isn't a path)
        if (waypointsCount.intValue < 2)
        {
            //button to create path manually
            if (GUILayout.Button("Create Path from Children"))
            {
                Undo.RecordObjects(waypoints, "Create Path");
                (targetClass.targetObject as PathManager).Create();
                SceneView.RepaintAll();
            }

            return;
        }

        //create new checkboxes for path gizmo property
        check1.boolValue = EditorGUILayout.Toggle("Draw Smooth Lines", check1.boolValue);

        //create new property fields for editing waypoint gizmo colors
        EditorGUILayout.PropertyField(color1);
        EditorGUILayout.PropertyField(color2);

        //calculate path length of all waypoints
        Vector3[] wpPositions = new Vector3[waypoints.Length];
        for (int i = 0; i < waypoints.Length; i++)
        {
            wpPositions[i] = waypoints[i].position;
        }

        //button for switching over to the WaypointManager for further path editing
        if (GUILayout.Button("Continue Editing"))
        {
            Selection.activeGameObject = (GameObject.FindObjectOfType(typeof(WaypointManager)) as WaypointManager).gameObject;
            WaypointEditor.ContinuePath(targetClass.targetObject as PathManager);
        }

        EditorGUILayout.Space();

        //waypoint index header
        GUILayout.Label("Waypoints: ", EditorStyles.boldLabel);

        float pathLength = WaypointManager.GetPathLength(wpPositions);

        //path length label, show calculated path length
        GUILayout.Label("Path Length: " + pathLength);

        //loop through the waypoint array
        for (int i = 0; i < waypoints.Length; i++)
        {
            GUILayout.BeginHorizontal();
            //indicate each array slot with index number in front of it
            GUILayout.Label(i + ".", GUILayout.Width(20));
            //create an object field for every waypoint
            EditorGUILayout.ObjectField(waypoints[i], typeof(Transform), true);

            //display an "Add Waypoint" button for every array row except the last one
            if (i < waypoints.Length && GUILayout.Button("+", GUILayout.Width(30f)))
            {
                AddWaypointAtIndex(i);
                break;
            }

            //display an "Remove Waypoint" button for every array row except the first and last one
            if (i > 0 && i < waypoints.Length - 1 && GUILayout.Button("-", GUILayout.Width(30f)))
            {
                RemoveWaypointAtIndex(i);
                break;
            }

            GUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Place To Ground", GUILayout.Height(35)))
        {
            PlaceToGround(waypoints);
        }
        if (GUILayout.Button("Rename Now", GUILayout.Height(35)))
        {
            RenameWaypoints(waypoints);
        }
        if (GUILayout.Button("Invert Direction", GUILayout.Height(35)))
        {
            InvertDirection(waypoints);
        }
        if (GUILayout.Button("Repath (Children Based)", GUILayout.Height(35)))
        {
            (targetClass.targetObject as PathManager).Create();
            SceneView.RepaintAll();
        }
        EditorGUILayout.EndHorizontal();

        //we push our modified variables back to our serialized object
        targetClass.ApplyModifiedProperties();
    }
示例#38
0
        private void OnSceneGUIDelegate(SceneView sceneView)
        {
            Event evt = Event.current;

            if (evt.type != EventType.DragUpdated && evt.type != EventType.DragPerform && evt.type != EventType.DragExited && evt.type != EventType.Repaint)
            {
                return;
            }

            Grid activeGrid = GetActiveGrid();

            if (activeGrid == null || DragAndDrop.objectReferences.Length == 0)
            {
                return;
            }

            Vector3    localMouse        = GridEditorUtility.ScreenToLocal(activeGrid.transform, evt.mousePosition);
            Vector3Int mouseGridPosition = activeGrid.LocalToCell(localMouse);

            switch (evt.type)
            {
            //TODO: Cache this
            case EventType.DragUpdated:
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                List <TileBase> tiles = TileDragAndDrop.GetValidTiles(DragAndDrop.objectReferences);
                instance.m_HoverData = TileDragAndDrop.CreateHoverData(null, null, tiles);
                if (instance.m_HoverData.Count > 0)
                {
                    Event.current.Use();
                    GUI.changed = true;
                }
                break;

            case EventType.DragPerform:
                if (instance.m_HoverData.Count > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    Dictionary <Vector2Int, TileBase> tileSheet = TileDragAndDrop.ConvertToTileSheet(instance.m_HoverData);
                    Tilemap tilemap = GetOrCreateActiveTilemap();
                    tilemap.ClearAllEditorPreviewTiles();
                    foreach (KeyValuePair <Vector2Int, TileBase> item in tileSheet)
                    {
                        Vector3Int position = new Vector3Int(mouseGridPosition.x + item.Key.x, mouseGridPosition.y + item.Key.y, 0);
                        tilemap.SetTile(position, item.Value);
                    }
                    instance.m_HoverData = null;
                    GUI.changed          = true;
                    Event.current.Use();
                }
                break;

            case EventType.Repaint:
                if (instance.m_HoverData != null)
                {
                    Tilemap map = Selection.activeGameObject.GetComponentInParent <Tilemap>();

                    if (map != null)
                    {
                        map.ClearAllEditorPreviewTiles();
                    }

                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    foreach (KeyValuePair <Vector2Int, Object> item in instance.m_HoverData)
                    {
                        Vector3Int gridPos = mouseGridPosition + new Vector3Int(item.Key.x, item.Key.y, 0);
                        if (item.Value is TileBase)
                        {
                            TileBase tile = item.Value as TileBase;
                            if (map != null)
                            {
                                map.SetEditorPreviewTile(gridPos, tile);
                            }
                        }
                    }
                }
                break;
            }

            if (instance.m_HoverData != null && (
                    Event.current.type == EventType.DragExited ||
                    Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape))
            {
                if (instance.m_HoverData.Count > 0)
                {
                    Tilemap map = Selection.activeGameObject.GetComponentInParent <Tilemap>();
                    if (map != null)
                    {
                        map.ClearAllEditorPreviewTiles();
                    }

                    Event.current.Use();
                }

                instance.m_HoverData = null;
            }
        }
示例#39
0
 private static void HandleWindowsGUI(SceneView sceneView)
 {
     SceneViewWindow.OnSceneView(sceneView);
 }
示例#40
0
    void DoWin(int id)
    {
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(new GUIContent("Ins Before", "Shift-G")))
        {
            InsBefore();
        }

        if (GUILayout.Button(new GUIContent("Ins After", "G")))
        {
            InsAfter();
        }

        if (GUILayout.Button(new GUIContent("Delete", "H")))
        {
            Delete();
        }

        if (Target)
        {
            if (Target.PreviousTransform && GUILayout.Button(new GUIContent("Prev", "Shift-T")))
            {
                Selection.activeTransform = Target.PreviousTransform;
            }
            if (Target.NextTransform && GUILayout.Button(new GUIContent("Next", "T")))
            {
                Selection.activeTransform = Target.NextTransform;
            }
            if (GUILayout.Button("Spline"))
            {
                Selection.activeTransform = Target.Spline.transform;
            }
        }
        GUILayout.EndHorizontal();
        // TCB
        if (Target.Spline.Interpolation == CurvyInterpolation.TCB)
        {
            GUILayout.BeginHorizontal();
            Target.OverrideGlobalTension = GUILayout.Toggle(Target.OverrideGlobalTension, "T", GUILayout.ExpandWidth(false));
            if (Target.OverrideGlobalTension)
            {
                Target.StartTension = GUILayout.HorizontalSlider(Target.StartTension, -1, 1);
                if (!Target.SynchronizeTCB)
                {
                    Target.EndTension = GUILayout.HorizontalSlider(Target.EndTension, -1, 1);
                }
                else
                {
                    Target.EndTension = Target.StartTension;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            Target.OverrideGlobalContinuity = GUILayout.Toggle(Target.OverrideGlobalContinuity, "C", GUILayout.ExpandWidth(false));

            if (Target.OverrideGlobalContinuity)
            {
                Target.StartContinuity = GUILayout.HorizontalSlider(Target.StartContinuity, -1, 1);
                if (!Target.SynchronizeTCB)
                {
                    Target.EndContinuity = GUILayout.HorizontalSlider(Target.EndContinuity, -1, 1);
                }
                else
                {
                    Target.EndContinuity = Target.StartContinuity;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            Target.OverrideGlobalBias = GUILayout.Toggle(Target.OverrideGlobalBias, "B", GUILayout.ExpandWidth(false));
            if (Target.OverrideGlobalBias)
            {
                Target.StartBias = GUILayout.HorizontalSlider(Target.StartBias, -1, 1);
                if (!Target.SynchronizeTCB)
                {
                    Target.EndBias = GUILayout.HorizontalSlider(Target.EndBias, -1, 1);
                }
                else
                {
                    Target.EndBias = Target.StartBias;
                }
            }
            GUILayout.EndHorizontal();
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(Target);
            Target.Spline.Refresh(true, true, false);
            SceneView.RepaintAll();
            serializedObject.UpdateIfDirtyOrScript();
        }
    }
示例#41
0
    public override void OnInspectorGUI()
    {
        if (Event.current.type == EventType.Layout)
        {
            mValid = Target.IsValidSegment;
        }

        if (mValid && (Target.Spline.Closed || !Target.IsFirstSegment))
        {
            EditorGUILayout.PropertyField(tSmoothTangent, new GUIContent("Smooth End Tangent", "Smooth end tangent?"));
        }


        if (mValid && Target.Spline.Interpolation == CurvyInterpolation.TCB)
        {
            EditorGUILayout.PropertyField(tSyncStartEnd, new GUIContent("Synchronize TCB", "Synchronize Start and End Values"));
            EditorGUILayout.PropertyField(tOT, new GUIContent("Local Tension", "Override Spline Tension?"));
            if (tOT.boolValue)
            {
                EditorGUILayout.PropertyField(tT0, Target.SynchronizeTCB ? new GUIContent("Tension", "Tension") : new GUIContent("Start Tension", "Start Tension"));
                if (!Target.SynchronizeTCB)
                {
                    EditorGUILayout.PropertyField(tT1, new GUIContent("End Tension", "End Tension"));
                }
                else
                {
                    tT1.floatValue = tT0.floatValue;
                }
            }
            EditorGUILayout.PropertyField(tOC, new GUIContent("Local Continuity", "Override Spline Continuity?"));
            if (tOC.boolValue)
            {
                EditorGUILayout.PropertyField(tC0, Target.SynchronizeTCB ? new GUIContent("Continuity", "Continuity") : new GUIContent("Start Continuity", "Start Continuity"));
                if (!Target.SynchronizeTCB)
                {
                    EditorGUILayout.PropertyField(tC1, new GUIContent("End Continuity", "End Continuity"));
                }
                else
                {
                    tC1.floatValue = tC0.floatValue;
                }
            }
            EditorGUILayout.PropertyField(tOB, new GUIContent("Local Bias", "Override Spline Bias?"));
            if (tOB.boolValue)
            {
                EditorGUILayout.PropertyField(tB0, Target.SynchronizeTCB ? new GUIContent("Bias", "Bias") : new GUIContent("Start Bias", "Start Bias"));
                if (!Target.SynchronizeTCB)
                {
                    EditorGUILayout.PropertyField(tB1, new GUIContent("End Bias", "End Bias"));
                }
                else
                {
                    tB1.floatValue = tB0.floatValue;
                }
            }

            if (tOT.boolValue || tOC.boolValue || tOB.boolValue)
            {
                EditorGUILayout.BeginHorizontal();

                if (GUILayout.Button("Set Catmul"))
                {
                    tT0.floatValue = 0; tC0.floatValue = 0; tB0.floatValue = 0;
                    tT1.floatValue = 0; tC1.floatValue = 0; tB1.floatValue = 0;
                }
                if (GUILayout.Button("Set Cubic"))
                {
                    tT0.floatValue = -1; tC0.floatValue = 0; tB0.floatValue = 0;
                    tT1.floatValue = -1; tC1.floatValue = 0; tB1.floatValue = 0;
                }
                if (GUILayout.Button("Set Linear"))
                {
                    tT0.floatValue = 0; tC0.floatValue = -1; tB0.floatValue = 0;
                    tT1.floatValue = 0; tC1.floatValue = -1; tB1.floatValue = 0;
                }
                EditorGUILayout.EndHorizontal();
            }
        }


        if (Target.UserValues != null && Target.UserValues.Length > 0)
        {
            EditorGUILayout.LabelField("User Values", EditorStyles.boldLabel);
            ArrayGUI(serializedObject, "UserValues", false);
        }

        GUILayout.Label("Tools", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(new GUIContent(mTexConstraints, "Constraints Tools"), GUILayout.ExpandWidth(false)))
        {
            CurvyConstraintsWin.Create();
        }
        GUI.enabled = Target.ControlPointIndex > 0;
        if (GUILayout.Button(new GUIContent(mTexSetFirstCP, "Set as first Control Point"), GUILayout.ExpandWidth(false)))
        {
            Undo.RegisterSceneUndo("Set First Control Point");
            CurvyUtility.setFirstCP(Target);
        }
        GUI.enabled = true;

        GUILayout.EndHorizontal();

        if (serializedObject.targetObject && serializedObject.ApplyModifiedProperties())
        {
            Target.Spline.Refresh(true, true, false);
            SceneView.RepaintAll();
        }

        if (mValid)
        {
            EditorGUILayout.LabelField("Segment Info", EditorStyles.boldLabel);
            EditorGUILayout.LabelField("Distance: " + Target.Distance);
            EditorGUILayout.LabelField("Length: " + Target.Length);
            EditorGUILayout.LabelField("Spline Length: " + Target.Spline.Length);
        }
    }
示例#42
0
        public override void OnSceneViewGUI(SceneView sceneView)
        {
            // TODO: This is not responsive.
            if (Manager.KeyEscapeDown)
            {
                ChangeMode(Mode.None);
                EditorUtility.SetDirty(Assembly);
            }

            if (m_mode == Mode.RigidBody)
            {
                if (Manager.HijackLeftMouseClick())
                {
                    Predicate <GameObject> filter = m_subMode == SubMode.None            ? new Predicate <GameObject>(obj => { return(obj != null && obj.GetComponent <Shape>() == null); }) :
                                                    m_subMode == SubMode.SelectRigidBody ? new Predicate <GameObject>(obj => { return(obj != null && obj.GetComponentInParent <RigidBody>() != null); }) :
                                                    null;

                    if (filter == null)
                    {
                        Debug.LogError("Unknown sub-mode in assembly tool.", Assembly);
                        return;
                    }

                    var hitResults = Utils.Raycast.IntersectChildren(HandleUtility.GUIPointToWorldRay(Event.current.mousePosition),
                                                                     Assembly.gameObject,
                                                                     filter);
                    if (hitResults.Length > 0)
                    {
                        // TODO: If count > 1 - the user should be able to chose which object to select.
                        GameObject selected = hitResults[0].Target;
                        if (m_subMode == SubMode.SelectRigidBody)
                        {
                            if (m_rbSelection != null && m_rbSelection.RigidBody == selected.GetComponentInParent <RigidBody>())
                            {
                                m_rbSelection = null;
                            }
                            else
                            {
                                m_rbSelection = new RigidBodySelection(selected.GetComponentInParent <RigidBody>());
                            }
                        }
                        else
                        {
                            int selectedIndex = m_selection.FindIndex(entry => { return(entry.Object == selected); });
                            // New entry, add it.
                            if (selectedIndex < 0)
                            {
                                m_selection.Add(new SelectionEntry(selected));
                            }
                            // Remove selected entry if it already exist.
                            else
                            {
                                m_selection.RemoveAt(selectedIndex);
                            }
                        }

                        EditorUtility.SetDirty(Assembly);
                    }
                }
            }
            else if (m_mode == Mode.Shape)
            {
                // ShapeCreateTool on scene view handles this.
            }
            else if (m_mode == Mode.Constraint)
            {
                // ConstraintCreateTool on scene view handles this.
            }
        }