コード例 #1
0
        public virtual void OnBeginDrag(PointerEventData eventData)
        {
            if (m_prefab == null)
            {
                return;
            }

            IScenePivot scenePivot = m_scene.IOCContainer.Resolve <IScenePivot>();

            m_dragPlane = GetDragPlane(m_scene.Camera, m_scene.Pointer, scenePivot.SecondaryPivot.position);

            bool wasPrefabEnabled = m_prefab.activeSelf;

            m_prefab.SetActive(false);

            Vector3    point;
            Quaternion rotation;

            if (GetPointOnDragPlane(m_scene.Camera, m_scene.Pointer, out point, out rotation))
            {
                m_prefabInstance = InstantiatePrefab(m_prefab, point, rotation);
            }
            else
            {
                m_prefabInstance = InstantiatePrefab(m_prefab, Vector3.zero, Quaternion.identity);
            }

            m_prefabInstanceTransforms = new HashSet <Transform>(m_prefabInstance.GetComponentsInChildren <Transform>(true));
            m_prefab.SetActive(wasPrefabEnabled);

            ExposeToEditor exposeToEditor = ExposeToEditor(m_prefabInstance);

            exposeToEditor.SetName(m_prefab.name);
            m_prefabInstance.SetActive(true);
        }
コード例 #2
0
        protected override void Update()
        {
            base.Update();

            if (m_editor.Tools.IsViewing)
            {
                return;
            }

            if (!m_handle.IsWindowActive || !m_handle.Window.IsPointerOver)
            {
                return;
            }

            if (ChangePositionAction() && !m_handle.IsDragging && m_handle.SelectedAxis == RuntimeHandleAxis.None)
            {
                TerrainAreaHandle.ChangePosition();
            }

            if (FocusAction() && m_handle != null && m_handle.IsWindowActive)
            {
                IScenePivot pivot = m_editor.GetScenePivot();
                Vector3[]   areaResizerPositions = TerrainAreaHandle.AreaResizerPositions;
                pivot.Focus(m_handle.Position, Mathf.Max(TerrainAreaHandle.Appearance.HandleScale, (areaResizerPositions[1] - areaResizerPositions[0]).magnitude));
            }
        }
コード例 #3
0
        protected virtual void AwakeOverride()
        {
            m_rte = RTE;
            IOC.Register <IRTE>(m_rte);
            IOC.Register(m_rte);

            m_scenePivot      = ScenePivot;
            m_resourcePreview = ResourcePreview;
            m_rteAppearance   = RTEAppearance;
        }
コード例 #4
0
ファイル: SceneViewImpl.cs プロジェクト: lbm7926/Imp
        protected virtual void OnAssetItemLoaded(Error error, Object[] obj)
        {
            if (obj[0] is GameObject)
            {
                IScenePivot scenePivot = IOCContainer.Resolve <IScenePivot>();
                Vector3     up         = Vector3.up;
                if (Mathf.Abs(Vector3.Dot(Camera.transform.up, Vector3.up)) > Mathf.Cos(Mathf.Deg2Rad))
                {
                    up = Vector3.Cross(Camera.transform.right, Vector3.up);
                }
                else
                {
                    up = Vector3.up;
                }
                m_dragPlane = GetDragPlane(scenePivot, up);

                GameObject prefab           = (GameObject)obj[0];
                bool       wasPrefabEnabled = prefab.activeSelf;
                prefab.SetActive(false);

                Vector3 point;
                if (GetPointOnDragPlane(out point))
                {
                    m_prefabInstance = InstantiatePrefab(prefab, point, Quaternion.identity);
                }
                else
                {
                    m_prefabInstance = InstantiatePrefab(prefab, Vector3.zero, Quaternion.identity);
                }

                Debug.Log(m_prefabInstance.GetComponentsInChildren <MeshFilter>().Length);

                m_prefabInstanceTransforms = new HashSet <Transform>(m_prefabInstance.GetComponentsInChildren <Transform>(true));

                prefab.SetActive(wasPrefabEnabled);

                Transform[] transforms = m_prefabInstance.GetComponentsInChildren <Transform>();
                foreach (Transform transform in transforms)
                {
                    ExposeToEditor exposeToEditor = transform.GetComponent <ExposeToEditor>();
                    if (exposeToEditor == null)
                    {
                        exposeToEditor = transform.gameObject.AddComponent <ExposeToEditor>();
                    }
                }

                {
                    ExposeToEditor exposeToEditor = m_prefabInstance.GetComponent <ExposeToEditor>();
                    exposeToEditor.SetName(obj[0].name);
                }


                OnActivatePrefabInstance(m_prefabInstance);
            }
        }
コード例 #5
0
        public override void DragEnter(object[] dragObjects, PointerEventData eventData)
        {
            base.DragEnter(dragObjects, eventData);
            if (Editor.DragDrop.DragObjects[0] is AssetItem)
            {
                AssetItem assetItem = (AssetItem)Editor.DragDrop.DragObjects[0];
                if (m_project.ToType(assetItem) == typeof(GameObject))
                {
                    Editor.DragDrop.SetCursor(KnownCursor.DropAllowed);
                    Editor.IsBusy = true;
                    m_project.Load(assetItem, (error, obj) =>
                    {
                        Editor.IsBusy = false;
                        if (IsPointerOver)
                        {
                            if (obj is GameObject)
                            {
                                IScenePivot scenePivot = IOCContainer.Resolve <IScenePivot>();
                                Vector3 up             = Vector3.up;
                                if (Mathf.Abs(Vector3.Dot(Camera.transform.up, Vector3.up)) > Mathf.Cos(Mathf.Deg2Rad))
                                {
                                    up = Vector3.Cross(Camera.transform.right, Vector3.up);
                                }
                                else
                                {
                                    up = Vector3.up;
                                }
                                m_dragPlane = new Plane(up, scenePivot.SecondaryPivot.position);

                                GameObject prefab     = (GameObject)obj;
                                bool wasPrefabEnabled = prefab.activeSelf;
                                prefab.SetActive(false);

                                m_prefabInstance = Instantiate(prefab, Vector3.zero, Quaternion.identity);

                                prefab.SetActive(wasPrefabEnabled);

                                ExposeToEditor exposeToEditor = m_prefabInstance.GetComponent <ExposeToEditor>();
                                if (exposeToEditor == null)
                                {
                                    exposeToEditor = m_prefabInstance.AddComponent <ExposeToEditor>();
                                }

                                exposeToEditor.SetName(obj.name);
                                m_prefabInstance.SetActive(true);
                            }
                        }
                    });
                }
            }
        }
コード例 #6
0
        public static void AddGameObjectToScene(this IRTE editor, GameObject go)
        {
            Vector3     pivot      = Vector3.zero;
            IScenePivot scenePivot = editor.GetScenePivot();

            if (scenePivot != null)
            {
                pivot = scenePivot.SecondaryPivot;
            }
            go.transform.position = pivot;
            go.AddComponent <ExposeToEditor>();
            go.SetActive(true);
            editor.RegisterCreatedObjects(new[] { go });
        }
コード例 #7
0
        private void CreateDragPlane()
        {
            IScenePivot scenePivot = IOCContainer.Resolve <IScenePivot>();
            Vector3     up         = Vector3.up;

            if (Mathf.Abs(Vector3.Dot(Camera.transform.up, Vector3.up)) > Mathf.Cos(Mathf.Deg2Rad))
            {
                up = Vector3.Cross(Camera.transform.right, Vector3.up);
            }
            else
            {
                up = Vector3.up;
            }
            m_dragPlane = GetDragPlane(scenePivot, up);
        }
コード例 #8
0
        private void GetPositionAndRotation(RuntimeWindow window, out Vector3 position, out Quaternion rotation, bool rotateToTerrain = false)
        {
            Ray ray = window != null ?
                      new Ray(window.Camera.transform.position, window.Camera.transform.forward) :
                      new Ray(Vector3.up * 100000, Vector3.down);

            RaycastHit[] hits = Physics.RaycastAll(ray);
            for (int i = 0; i < hits.Length; ++i)
            {
                RaycastHit hit = hits[i];
                if (hit.collider is TerrainCollider)
                {
                    position = hit.point;
                    if (rotateToTerrain)
                    {
                        rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
                    }
                    else
                    {
                        rotation = Quaternion.identity;
                    }
                    return;
                }
            }

            Vector3 up    = Vector3.up;
            Vector3 pivot = Vector3.zero;

            if (window != null)
            {
                IScenePivot scenePivot = window.IOCContainer.Resolve <IScenePivot>();
                if (Mathf.Abs(Vector3.Dot(window.Camera.transform.up, Vector3.up)) > Mathf.Cos(Mathf.Deg2Rad))
                {
                    up = Vector3.Cross(window.Camera.transform.right, Vector3.up);
                }

                pivot = scenePivot.SecondaryPivot;
            }

            Plane dragPlane = new Plane(up, pivot);

            rotation = Quaternion.identity;
            if (!GetPointOnDragPlane(ray, dragPlane, out position))
            {
                position = window.Camera.transform.position + window.Camera.transform.forward * 10.0f;
            }
        }
コード例 #9
0
ファイル: GameObjectCmd.cs プロジェクト: huhuman/NadiSensoUI
        private IScenePivot GetScenePivot()
        {
            if (m_editor.ActiveWindow != null)
            {
                IScenePivot scenePivot = m_editor.ActiveWindow.IOCContainer.Resolve <IScenePivot>();
                if (scenePivot != null)
                {
                    return(scenePivot);
                }
            }

            RuntimeWindow sceneWindow = m_editor.GetWindow(RuntimeWindowType.Scene);

            if (sceneWindow != null)
            {
                IScenePivot scenePivot = sceneWindow.IOCContainer.Resolve <IScenePivot>();
                if (scenePivot != null)
                {
                    return(scenePivot);
                }
            }

            return(null);
        }
コード例 #10
0
        public static IScenePivot GetScenePivot(this IRTE editor)
        {
            if (editor.ActiveWindow != null)
            {
                IScenePivot scenePivot = editor.ActiveWindow.IOCContainer.Resolve <IScenePivot>();
                if (scenePivot != null)
                {
                    return(scenePivot);
                }
            }

            RuntimeWindow sceneWindow = editor.GetWindow(RuntimeWindowType.Scene);

            if (sceneWindow != null)
            {
                IScenePivot scenePivot = sceneWindow.IOCContainer.Resolve <IScenePivot>();
                if (scenePivot != null)
                {
                    return(scenePivot);
                }
            }

            return(null);
        }
コード例 #11
0
        private void OnFocusClick()
        {
            IScenePivot scenePivot = Editor.GetWindow(RuntimeWindowType.Scene).IOCContainer.Resolve <IScenePivot>();

            scenePivot.Focus(FocusMode.Default);
        }
コード例 #12
0
ファイル: SceneViewImpl.cs プロジェクト: lbm7926/Imp
 protected virtual Plane GetDragPlane(IScenePivot scenePivot, Vector3 up)
 {
     return(new Plane(up, scenePivot.SecondaryPivot));
 }
コード例 #13
0
ファイル: GameObjectCmd.cs プロジェクト: huhuman/NadiSensoUI
        public void Exec(string cmd)
        {
            cmd = cmd.ToLower();
            GameObject go = null;

            switch (cmd)
            {
            case "createempty":
                go      = new GameObject();
                go.name = "Empty";
                break;

            case "createemptychild":
                go      = new GameObject();
                go.name = "Empty";
                IRuntimeSelection selection = m_editor.Selection;
                go.transform.SetParent(selection.activeTransform, false);
                break;

            case "cube":
                go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                break;

            case "sphere":
                go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                break;

            case "capsule":
                go = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                break;

            case "cylinder":
                go = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                break;

            case "plane":
                go = GameObject.CreatePrimitive(PrimitiveType.Plane);
                break;

            case "quad":
                go = GameObject.CreatePrimitive(PrimitiveType.Quad);
                break;

            case "directionallight":
            {
                go      = new GameObject();
                go.name = "Directional Light";
                Light light = go.AddComponent <Light>();
                light.type = LightType.Directional;
            }
            break;

            case "pointlight":
            {
                go      = new GameObject();
                go.name = "Point Light";
                Light light = go.AddComponent <Light>();
                light.type = LightType.Point;
            }
            break;

            case "spotlight":
            {
                go      = new GameObject();
                go.name = "Spot Light";
                Light light = go.AddComponent <Light>();
                light.type = LightType.Point;
            }
            break;

            case "camera":
            {
                go = new GameObject();
                go.SetActive(false);
                go.name = "Camera";
                go.AddComponent <Camera>();
                go.AddComponent <GameViewCamera>();
            }
            break;
            }

            if (go != null)
            {
                Vector3     pivot      = Vector3.zero;
                IScenePivot scenePivot = GetScenePivot();
                if (scenePivot != null)
                {
                    pivot = scenePivot.SecondaryPivot.position;
                }
                go.transform.position = pivot;
                go.AddComponent <ExposeToEditor>();
                go.SetActive(true);
                m_editor.RegisterCreatedObjects(new[] { go });
            }
        }
コード例 #14
0
ファイル: GameObjectCmd.cs プロジェクト: lbm7926/Imp
        public void Exec(string cmd)
        {
            cmd = cmd.ToLower();
            GameObject go = null;

            switch (cmd)
            {
            case "createempty":
                go      = new GameObject();
                go.name = "Empty";
                break;

            case "createemptychild":
                go      = new GameObject();
                go.name = "Empty";
                IRuntimeSelection selection = m_editor.Selection;
                go.transform.SetParent(selection.activeTransform, false);
                break;

            case "cube":
                go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                go.GetComponent <Renderer>().sharedMaterial = m_defaultMaterial;
                break;

            case "sphere":
                go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                go.GetComponent <Renderer>().sharedMaterial = m_defaultMaterial;
                break;

            case "capsule":
                go = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                go.GetComponent <Renderer>().sharedMaterial = m_defaultMaterial;
                break;

            case "cylinder":
                go = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                go.GetComponent <Renderer>().sharedMaterial = m_defaultMaterial;
                break;

            case "plane":
                go = GameObject.CreatePrimitive(PrimitiveType.Plane);
                go.GetComponent <Renderer>().sharedMaterial = m_defaultMaterial;
                break;

            case "quad":
                go = GameObject.CreatePrimitive(PrimitiveType.Quad);
                go.GetComponent <Renderer>().sharedMaterial = m_defaultMaterial;
                break;

            case "directionallight":
            {
                go      = new GameObject();
                go.name = "Directional Light";
                Light light = go.AddComponent <Light>();
                light.type = LightType.Directional;
            }
            break;

            case "pointlight":
            {
                go      = new GameObject();
                go.name = "Point Light";
                Light light = go.AddComponent <Light>();
                light.type = LightType.Point;
            }
            break;

            case "spotlight":
            {
                go      = new GameObject();
                go.name = "Spot Light";
                Light light = go.AddComponent <Light>();
                light.type = LightType.Point;
            }
            break;

            case "camera":
            {
                go = new GameObject();
                go.SetActive(false);
                go.name = "Camera";
                go.AddComponent <Camera>();
                go.AddComponent <GameViewCamera>();
            }
            break;

                #region Imp
            case "机器人":
                go      = Instantiate(Resources.Load("Model/" + cmd) as GameObject);
                go.name = cmd;
                break;

            case "总控":
                go      = Instantiate(Resources.Load("Model/" + cmd) as GameObject);
                go.name = cmd;
                break;

            case "总控电气柜":
                go      = Instantiate(Resources.Load("Model/" + cmd) as GameObject);
                go.name = cmd;
                break;

            case "抽拉底座":
                go      = Instantiate(Resources.Load("Model/" + cmd) as GameObject);
                go.name = cmd;
                break;

            case "立体库":
                go      = Instantiate(Resources.Load("Model/" + cmd) as GameObject);
                go.name = cmd;
                break;

            case "车床":
                go      = Instantiate(Resources.Load("Model/" + cmd) as GameObject);
                go.name = cmd;
                break;

            case "输送机":
                go      = Instantiate(Resources.Load("Model/" + cmd) as GameObject);
                go.name = cmd;
                break;

            case "铣床":
                go      = Instantiate(Resources.Load("Model/" + cmd) as GameObject);
                go.name = cmd;
                break;
                #endregion
            }

            if (go != null)
            {
                Vector3     pivot      = Vector3.zero;
                IScenePivot scenePivot = GetScenePivot();
                if (scenePivot != null)
                {
                    pivot = scenePivot.SecondaryPivot;
                }
                go.transform.position = pivot;
                go.AddComponent <ExposeToEditor>();

                Modle equipment = new Modle()
                {
                    modleName = go.name,
                    position  = Util.Vector3ToVector3d(go.transform.position),
                    rotation  = Util.Vector3ToVector3d(go.transform.localRotation.eulerAngles)
                };
                //go.AddComponent<Equipment>();

                go.SetActive(true);
                m_editor.RegisterCreatedObjects(new[] { go });

                RuntimeEditor.modelDic.Add(go, equipment);
                RuntimeEditor.solutionInfo.equipmentList.Add(equipment);
            }
        }
コード例 #15
0
        private LayoutInfo DefaultLayout(IWindowManager wm)
        {
            bool isDialog;

            WindowDescriptor sceneWd;
            GameObject       sceneContent;

            wm.CreateWindow(RuntimeWindowType.Scene.ToString(), out sceneWd, out sceneContent, out isDialog);

            WindowDescriptor sceneXWd;
            GameObject       sceneXContent;
            RuntimeWindow    xWindow = wm.CreateWindow(RuntimeWindowType.Scene.ToString(), out sceneXWd, out sceneXContent, out isDialog).GetComponent <RuntimeWindow>();

            // xWindow.CanActivate = false;

            RunNextFrame(() =>
            {
                IScenePivot xPivot    = xWindow.IOCContainer.Resolve <IScenePivot>();
                xPivot.Pivot.position = new Vector3(5, 0, 0);

                xWindow.Camera.transform.position = Vector3.right * 20;
                xWindow.Camera.transform.LookAt(xPivot.Pivot);
                xWindow.Camera.orthographic = true;

                PositionHandle positionHandle = wm.GetComponents(xWindow.transform).SelectMany(c => c.GetComponentsInChildren <PositionHandle>(true)).FirstOrDefault();
                positionHandle.GridSize       = 2;

                RotationHandle rotationHandle = wm.GetComponents(xWindow.transform).SelectMany(c => c.GetComponentsInChildren <RotationHandle>(true)).FirstOrDefault();
                rotationHandle.GridSize       = 5;

                Tab tab = Region.FindTab(xWindow.transform);
                tab.IsCloseButtonVisible = false;
            });

            WindowDescriptor gameWd;
            GameObject       gameContent;

            wm.CreateWindow(RuntimeWindowType.Game.ToString(), out gameWd, out gameContent, out isDialog);

            WindowDescriptor inspectorWd;
            GameObject       inspectorContent;

            wm.CreateWindow(RuntimeWindowType.Inspector.ToString(), out inspectorWd, out inspectorContent, out isDialog);

            WindowDescriptor hierarchyWd;
            GameObject       hierarchyContent;

            wm.CreateWindow(RuntimeWindowType.Hierarchy.ToString(), out hierarchyWd, out hierarchyContent, out isDialog);

            LayoutInfo layout = new LayoutInfo(false,
                                               new LayoutInfo(true,
                                                              new LayoutInfo(
                                                                  new LayoutInfo(sceneContent.transform, sceneWd.Header, sceneWd.Icon),
                                                                  new LayoutInfo(gameContent.transform, gameWd.Header, gameWd.Icon)),
                                                              new LayoutInfo(sceneXContent.transform, sceneXWd.Header, sceneXWd.Icon),
                                                              0.5f),
                                               new LayoutInfo(true,
                                                              new LayoutInfo(inspectorContent.transform, inspectorWd.Header, inspectorWd.Icon),
                                                              new LayoutInfo(hierarchyContent.transform, hierarchyWd.Header, hierarchyWd.Icon),
                                                              0.5f),
                                               0.75f);

            return(layout);
        }