Exemplo n.º 1
0
            /// <summary>
            /// 获取已经打开的UI
            /// </summary>
            /// <param name="type">UI逻辑类</param>
            /// <returns>UI逻辑对象</returns>
            public UILogicBase GetOpenedUI(Type type)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogicBase ui = _worldUIs[type];

                    if (ui.IsOpened)
                    {
                        return(ui);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("获取UI失败:UI对象 {0} 并未存在,或并未打开!", type.Name));
                    return(null);
                }
            }
Exemplo n.º 2
0
 /// <summary>
 /// 发起网络请求
 /// </summary>
 public void SendRequest(string interfaceName, WWWForm form)
 {
     if (IsExistInterface(interfaceName))
     {
         if (IsOfflineState)
         {
             if (_interfaces[interfaceName].OfflineHandler != null)
             {
                 _interfaces[interfaceName].OfflineHandler();
             }
         }
         else
         {
             StartCoroutine(SendRequestCoroutine(interfaceName, form));
         }
     }
     else
     {
         GlobalTools.LogError("发起网络请求失败:不存在名为 " + interfaceName + " 的网络接口!");
     }
 }
Exemplo n.º 3
0
        private void SetHotfixAssemblyDefinition(string filePath)
        {
            string   contentOld = File.ReadAllText(filePath);
            JsonData json       = GlobalTools.StringToJson(contentOld);

            json["name"]             = "Hotfix";
            json["includePlatforms"] = new JsonData();
            json["includePlatforms"].Add("Editor");
            json["references"] = new JsonData();
            json["references"].Add("HTFramework.RunTime");
            json["autoReferenced"] = false;
            string contentNew = GlobalTools.JsonToString(json);

            if (contentOld != contentNew)
            {
                File.WriteAllText(filePath, contentNew);
                AssetDatabase.Refresh();
                AssemblyDefinitionImporter importer = AssetImporter.GetAtPath("Assets" + _hotfixAssemblyDefinitionPath) as AssemblyDefinitionImporter;
                importer.SaveAndReimport();
            }
        }
Exemplo n.º 4
0
        private void SwitchAngle(bool damping)
        {
            //摄像机插值变换到新的位置
            if (damping)
            {
                transform.rotation = Quaternion.Lerp(transform.rotation, _rotation, Time.deltaTime * _damping);
                transform.position = Vector3.Lerp(transform.position, _position, Time.deltaTime * _damping);
            }
            //摄像机直接变换到新的位置
            else
            {
                transform.rotation = _rotation;
                transform.position = _position;
            }

            //摄像机位置限制
            if (NeedLimit)
            {
                transform.position = GlobalTools.Clamp(transform.position, XMinLimit, YMinLimit, ZMinLimit, XMaxLimit, YMaxLimit, ZMaxLimit);
            }
        }
Exemplo n.º 5
0
 private IEnumerator SendInfoCoroutine(byte[] sendBytes)
 {
     _isSending = true;
     while (_sendDataBuffer.Count > 0)
     {
         try
         {
             int sendNum = _client.Send(_sendDataBuffer[0], _sendDataBuffer[0].Length, 0);
             if (sendNum > 0)
             {
                 _sendDataBuffer.RemoveAt(0);
             }
         }
         catch (Exception e)
         {
             GlobalTools.LogError("发送数据出错:" + e.ToString());
         }
         yield return(0);
     }
     _isSending = false;
 }
Exemplo n.º 6
0
 /// <summary>
 /// 通过名称获取参数
 /// </summary>
 /// <param name="parameterName">参数名称</param>
 /// <returns>参数</returns>
 public StepParameter GetParameter(string parameterName)
 {
     if (Parameters == null)
     {
         GlobalTools.LogError(string.Format("步骤:{0}[ID:{1}]未获取到参数[{2}]!", Content.Name, Content.GUID, parameterName));
         return(null);
     }
     else
     {
         StepParameter stepParameter = Parameters.Find((p) => { return(p.Name == parameterName); });
         if (stepParameter != null)
         {
             return(stepParameter);
         }
         else
         {
             GlobalTools.LogError(string.Format("步骤:{0}[ID:{1}]未获取到参数[{2}]!", Content.Name, Content.GUID, parameterName));
             return(null);
         }
     }
 }
Exemplo n.º 7
0
 private void ColorSkip()
 {
     if (BoolValue)
     {
         if (!Target.GetComponent <Renderer>())
         {
             GlobalTools.LogError(string.Format("目标 {0} 丢失组件Renderer!无法播放颜色改变动画!", Target));
             return;
         }
         Target.GetComponent <Renderer>().material.DOColor(ColorValue, ElapseTime / StepMaster.SkipMultiple).SetEase(AnimationEase);
     }
     if (BoolValue2)
     {
         if (!Target.GetComponent <Graphic>())
         {
             GlobalTools.LogError(string.Format("目标 {0} 丢失组件Graphic!无法播放颜色改变动画!", Target));
             return;
         }
         Target.GetComponent <Graphic>().DOColor(ColorValue, ElapseTime / StepMaster.SkipMultiple).SetEase(AnimationEase);
     }
 }
Exemplo n.º 8
0
        private void RecoveryEntities(Type type)
        {
            EntityResourceAttribute attribute = type.GetCustomAttribute <EntityResourceAttribute>();

            if (attribute != null)
            {
                if (_entities.ContainsKey(type))
                {
                    if (attribute.IsUseObjectPool)
                    {
                        for (int i = 0; i < _entities[type].Count; i++)
                        {
                            EntityLogic entityLogic = _entities[type][i];
                            entityLogic.OnDestroy();
                            Main.m_ReferencePool.Despawn(entityLogic);
                            _objectPool[type].Enqueue(entityLogic.Entity);
                            entityLogic.Entity.SetActive(false);
                            entityLogic.Entity = null;
                        }
                        _entities[type].Clear();
                    }
                    else
                    {
                        for (int i = 0; i < _entities[type].Count; i++)
                        {
                            EntityLogic entityLogic = _entities[type][i];
                            entityLogic.OnDestroy();
                            Main.m_ReferencePool.Despawn(entityLogic);
                            Destroy(entityLogic.Entity);
                            entityLogic.Entity = null;
                        }
                        _entities[type].Clear();
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("销毁实体失败:实体对象 {0} 并未存在!", type.Name));
                }
            }
        }
Exemplo n.º 9
0
        private void ExtractEntity(Type type, HTFAction <float> loadingAction = null)
        {
            EntityResourceAttribute attribute = type.GetCustomAttribute <EntityResourceAttribute>();

            if (attribute != null)
            {
                if (_entities.ContainsKey(type))
                {
                    if (attribute.IsUseObjectPool && _objectPool[type].Count > 0)
                    {
                        EntityLogic entityLogic = Main.m_ReferencePool.Spawn(type) as EntityLogic;
                        entityLogic.Entity = _objectPool[type].Dequeue();
                        entityLogic.Entity.SetActive(true);
                        entityLogic.OnInit();
                        entityLogic.OnShow();
                        _entities[type].Add(entityLogic);

                        Main.m_Event.Throw(this, Main.m_ReferencePool.Spawn <EventCreateEntitySucceed>().Fill(entityLogic));
                    }
                    else
                    {
                        Main.m_Resource.LoadPrefab(new PrefabInfo(attribute), _entitiesGroup[type].transform, loadingAction, (obj) =>
                        {
                            EntityLogic entityLogic = Main.m_ReferencePool.Spawn(type) as EntityLogic;
                            entityLogic.Entity      = obj;
                            entityLogic.Entity.SetActive(true);
                            entityLogic.OnInit();
                            entityLogic.OnShow();
                            _entities[type].Add(entityLogic);

                            Main.m_Event.Throw(this, Main.m_ReferencePool.Spawn <EventCreateEntitySucceed>().Fill(entityLogic));
                        });
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("创建实体失败:实体对象 {0} 并未存在!", type.Name));
                }
            }
        }
Exemplo n.º 10
0
            /// <summary>
            /// 预加载非常驻UI
            /// </summary>
            /// <param name="type">非常驻UI逻辑类</param>
            /// <returns>加载协程</returns>
            public Coroutine PreloadingTemporaryUI(Type type)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogicBase ui = _worldUIs[type];

                    if (!ui.IsCreated)
                    {
                        return(Main.m_Resource.LoadPrefab(new PrefabInfo(type.GetCustomAttribute <UIResourceAttribute>()), _worldTemporaryPanel, null, (obj) =>
                        {
                            ui.UIEntity = obj;
                            ui.UIEntity.SetLayerIncludeChildren(_worldUIRoot.gameObject.layer);
                            ui.OnInit();
                        }, true));
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("预加载UI失败:UI对象 {0} 并未存在!", type.Name));
                }
                return(null);
            }
Exemplo n.º 11
0
        /// <summary>
        /// 切换状态
        /// </summary>
        public void SwitchState(Type type)
        {
            if (_stateInstances.ContainsKey(type))
            {
                if (_currentState == _stateInstances[type])
                {
                    return;
                }

                if (_currentState != null)
                {
                    _currentState.OnLeave();
                }

                _currentState = _stateInstances[type];
                _currentState.OnEnter();
            }
            else
            {
                GlobalTools.LogError("切换状态失败:有限状态机 " + Name + " 不存在状态 " + type.Name + "!");
            }
        }
Exemplo n.º 12
0
        private static void SetMouseRayTarget()
        {
            if (Selection.gameObjects.Length <= 0)
            {
                GlobalTools.LogWarning("请先选中场景中的物体!");
                return;
            }

            GameObject[] objs = Selection.gameObjects;
            for (int i = 0; i < objs.Length; i++)
            {
                if (!objs[i].GetComponent <Collider>())
                {
                    objs[i].AddComponent <BoxCollider>();
                }
                if (!objs[i].GetComponent <MouseRayTarget>())
                {
                    objs[i].AddComponent <MouseRayTarget>();
                }
                objs[i].GetComponent <MouseRayTarget>().Name = objs[i].name;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 切换流程
        /// </summary>
        public void SwitchProcedure <T>() where T : Procedure
        {
            if (_procedureInstances.ContainsKey(typeof(T)))
            {
                if (_currentProcedure == _procedureInstances[typeof(T)])
                {
                    return;
                }

                if (_currentProcedure != null)
                {
                    _currentProcedure.OnLeave();
                }

                _currentProcedure = _procedureInstances[typeof(T)];
                _currentProcedure.OnEnter();
            }
            else
            {
                GlobalTools.LogError("切换流程失败:不存在流程 " + typeof(T).Name + " 或者流程未激活!");
            }
        }
Exemplo n.º 14
0
        public override void OnInitialization()
        {
            base.OnInitialization();

#if UNITY_EDITOR
            IsHandler = false;
#endif

#if UNITY_STANDALONE_WIN
            FeedbackProgramPath = GlobalTools.GetDirectorySameLevelOfAssets(FeedbackProgramPath);
            _logPath            = GlobalTools.GetDirectorySameLevelOfAssets("/Log");
            if (!Directory.Exists(_logPath))
            {
                Directory.CreateDirectory(_logPath);
            }
#endif
            if (IsHandler)
            {
                Application.logMessageReceived += Handler;
                _sender = new EmailSender(SendMailbox, SendMailboxPassword, ReceiveMailbox, Host, Port);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// 切换状态
        /// </summary>
        public void SwitchState <T>() where T : FiniteState
        {
            if (_stateInstances.ContainsKey(typeof(T)))
            {
                if (_currentState == _stateInstances[typeof(T)])
                {
                    return;
                }

                if (_currentState != null)
                {
                    _currentState.OnLeave();
                }

                _currentState = _stateInstances[typeof(T)];
                _currentState.OnEnter();
            }
            else
            {
                GlobalTools.LogError("切换状态失败:有限状态机 " + Name + " 不存在状态 " + typeof(T).Name + "!");
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// 切换状态
        /// </summary>
        /// <param name="type">状态类型</param>
        public void SwitchState(Type type)
        {
            if (_stateInstances.ContainsKey(type))
            {
                if (_currentState == _stateInstances[type])
                {
                    return;
                }

                if (_currentState != null)
                {
                    _currentState.OnLeave();
                }

                _currentState = _stateInstances[type];
                _currentState.OnEnter();
            }
            else
            {
                GlobalTools.LogError(string.Format("切换状态失败:有限状态机 {0} 不存在状态 {1}!", Name, type.Name));
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// 平移注视视野
        /// </summary>
        /// <param name="position">目标位置</param>
        /// <param name="damping">阻尼缓动模式</param>
        public void SetPosition(Vector3 position, bool damping = true)
        {
            if (NeedLimit)
            {
                position = GlobalTools.Clamp(position, XMinLimit, YMinLimit, ZMinLimit, XMaxLimit, YMaxLimit, ZMaxLimit);
            }

            if (_moveTweener != null)
            {
                _moveTweener.Kill();
                _moveTweener = null;
            }

            if (damping)
            {
                _moveTweener = Target.transform.DOMove(position, DampingTime);
            }
            else
            {
                Target.transform.position = position;
            }
        }
Exemplo n.º 18
0
            /// <summary>
            /// 打开常驻UI
            /// </summary>
            /// <param name="type">常驻UI逻辑类</param>
            /// <param name="args">可选参数</param>
            /// <returns>加载协程</returns>
            public Coroutine OpenResidentUI(Type type, params object[] args)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogicResident ui = _worldUIs[type] as UILogicResident;

                    if (ui.IsOpened)
                    {
                        return(null);
                    }

                    if (!ui.IsCreated)
                    {
                        return(Main.m_Resource.LoadPrefab(new PrefabInfo(type.GetCustomAttribute <UIResourceAttribute>()), _worldResidentPanel, null, (obj) =>
                        {
                            ui.UIEntity = obj;
                            ui.UIEntity.SetLayerIncludeChildren(_worldUIRoot.gameObject.layer);
                            ui.UIEntity.transform.SetAsLastSibling();
                            ui.UIEntity.SetActive(true);
                            ui.OnInit();
                            ui.OnOpen(args);
                            ui.OnPlaceTop();
                        }, true));
                    }
                    else
                    {
                        ui.UIEntity.transform.SetAsLastSibling();
                        ui.UIEntity.SetActive(true);
                        ui.OnOpen(args);
                        ui.OnPlaceTop();
                    }
                }
                else
                {
                    GlobalTools.LogError(string.Format("打开UI失败:UI对象 {0} 并未存在!", type.Name));
                }
                return(null);
            }
Exemplo n.º 19
0
 private void MainDataAwake()
 {
     if (MainDataType != "<None>")
     {
         Type type = GlobalTools.GetTypeInRunTimeAssemblies(MainDataType);
         if (type != null)
         {
             if (type.IsSubclassOf(typeof(MainData)))
             {
                 _data = Activator.CreateInstance(type) as MainData;
                 _data.OnInit();
             }
             else
             {
                 GlobalTools.LogError("创建全局数据类失败:数据类 " + MainDataType + " 必须继承至基类:MainData!");
             }
         }
         else
         {
             GlobalTools.LogError("创建全局数据类失败:丢失数据类 " + MainDataType + "!");
         }
     }
 }
Exemplo n.º 20
0
 private void MainDataInitialization()
 {
     if (MainDataType != "<None>")
     {
         Type type = GlobalTools.GetTypeInRunTimeAssemblies(MainDataType);
         if (type != null)
         {
             if (type.IsSubclassOf(typeof(MainDataBase)))
             {
                 _data = Activator.CreateInstance(type) as MainDataBase;
                 _data.OnInitialization();
             }
             else
             {
                 GlobalTools.LogError(string.Format("创建全局数据类失败:数据类 {0} 必须继承至基类:MainDataBase!", MainDataType));
             }
         }
         else
         {
             GlobalTools.LogError(string.Format("创建全局数据类失败:丢失数据类 {0}!", MainDataType));
         }
     }
 }
Exemplo n.º 21
0
        public override void OnInitialization()
        {
            base.OnInitialization();

            List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies();

            for (int i = 0; i < types.Count; i++)
            {
                if (types[i].IsSubclassOf(typeof(CustomModuleBase)))
                {
                    CustomModuleAttribute att = types[i].GetCustomAttribute <CustomModuleAttribute>();
                    if (att != null && att.IsEnable && !_customModules.ContainsKey(att.ModuleName))
                    {
                        _customModules.Add(att.ModuleName, Activator.CreateInstance(types[i]) as CustomModuleBase);
                    }
                }
            }

            foreach (var module in _customModules)
            {
                module.Value.OnInitialization();
            }
        }
Exemplo n.º 22
0
        protected override void OnBodyGUI()
        {
            base.OnBodyGUI();

            if (EditorBuildSettings.scenes != null && EditorBuildSettings.scenes.Length > 0)
            {
                EditorBuildSettings.scenes = null;
                GlobalTools.LogWarning("只允许构建包含框架主体的场景!如有多场景切换的需求,请将其他场景打入AB包!");
            }

            if (!_isCanBuild)
            {
                BuildButtonMaskGUI();
            }

            _onGUIMethod.Invoke(_buildPlayerWindow, null);

            if (!_isCanBuild)
            {
                BuildButtonMaskGUI();
            }

            GUI.enabled = true;

            if (_isShowBuildABButton)
            {
                if (GUI.Button(new Rect(position.width - 422, position.height - 31, 123, 18), "Build AssetBundles"))
                {
                    AssetBundleBrowserMain.ShowWindow();
                }
            }
            if (GUI.Button(new Rect(position.width - 294, position.height - 31, 52, 18), "Check"))
            {
                CheckResourceMode();
                Check();
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// 刷新
        /// </summary>
        public void Refresh()
        {
            if (IsOpenRay)
            {
                if (GlobalTools.IsPointerOverUGUI())
                {
                    RaycastHiting(null);
                    return;
                }

                _ray = RayCamera.ScreenPointToRay(Main.m_Input.MousePosition);
                if (Physics.Raycast(_ray, out _hit, 100, ActivatedLayer))
                {
                    HitPoint = _hit.point;
                    RaycastHiting(_hit.transform.GetComponent <MouseRayTarget>());
                }
                else
                {
                    RaycastHiting(null);
                }

                RaycastHitImageFlow();
            }
        }
Exemplo n.º 24
0
 private void StaticExecute()
 {
     object[] parameters = new object[_parameters.Count];
     for (int i = 0; i < _parameters.Count; i++)
     {
         parameters[i] = _parameters[i].GetValue();
     }
     if (Method.IsStatic)
     {
         object returnValue = Method.Invoke(null, parameters);
         if (Method.ReturnType.Name != "Void")
         {
             GlobalTools.LogInfo("Execute " + _methodName + ", Return value is: " + (returnValue != null ? returnValue.ToString() : "null"));
         }
     }
     else
     {
         object returnValue = Method.Invoke(Target, parameters);
         if (Method.ReturnType.Name != "Void")
         {
             GlobalTools.LogInfo("Execute " + _methodName + ", Return value is: " + (returnValue != null ? returnValue.ToString() : "null"));
         }
     }
 }
Exemplo n.º 25
0
            /// <summary>
            /// 关闭UI
            /// </summary>
            /// <param name="type">UI逻辑类</param>
            public void CloseUI(Type type)
            {
                if (_worldUIs.ContainsKey(type))
                {
                    UILogic ui = _worldUIs[type];

                    if (!ui.IsCreated)
                    {
                        return;
                    }

                    if (!ui.IsOpened)
                    {
                        return;
                    }

                    ui.UIEntity.SetActive(false);
                    ui.OnClose();
                }
                else
                {
                    GlobalTools.LogError(string.Format("关闭UI失败:UI对象 {0} 并未存在!", type.Name));
                }
            }
Exemplo n.º 26
0
        /// <summary>
        /// 关闭UI
        /// </summary>
        public void CloseUI <T>() where T : UILogic
        {
            if (_UIs.ContainsKey(typeof(T)))
            {
                UILogic ui = _UIs[typeof(T)];

                if (!ui.IsCreated)
                {
                    return;
                }

                if (!ui.IsOpened)
                {
                    return;
                }

                ui.UIEntity.SetActive(false);
                ui.OnClose();
            }
            else
            {
                GlobalTools.LogError("关闭UI失败:UI对象 " + typeof(T).Name + " 并未存在!");
            }
        }
Exemplo n.º 27
0
        private void Start()
        {
            if (!transform.rectTransform())
            {
                GlobalTools.LogError(name + " 丢失组件rectTransform!不能执行UIAnimation!");
                Destroy(this);
                return;
            }
            _theGraphic = GetComponent <Graphic>();
            if (!_theGraphic)
            {
                if (TheAnimationType == UIAnimationType.Transparency || TheAnimationType == UIAnimationType.Color)
                {
                    GlobalTools.LogError(name + " 丢失组件Graphic!不能执行UIAnimation!");
                    Destroy(this);
                    return;
                }
            }

            if (PlayOnStart)
            {
                Play();
            }
        }
Exemplo n.º 28
0
        protected override void OnInspectorDefaultGUI()
        {
            base.OnInspectorDefaultGUI();

            #region Property
            GUILayout.BeginHorizontal("MeTransitionHead");
            GUILayout.Space(12);
            bool showProperty = EditorGUILayout.Foldout(_showProperty, "Property", true);
            if (showProperty != _showProperty)
            {
                _showProperty = showProperty;
                EditorPrefs.SetBool(EditorPrefsTable.Transform_Property, _showProperty);
            }
            GUILayout.EndHorizontal();

            if (_showProperty)
            {
                GUILayout.BeginVertical(EditorGlobalTools.Styles.Box);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Position", GUILayout.Width(80));
                Vector3 pos = EditorGUILayout.Vector3Field("", Target.position);
                if (pos != Target.position)
                {
                    Undo.RecordObject(Target, "Move " + Target.name);
                    Target.position = pos;
                    HasChanged();
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Rotation", GUILayout.Width(80));
                Vector3 rot = EditorGUILayout.Vector3Field("", Target.rotation.eulerAngles);
                if (rot != Target.rotation.eulerAngles)
                {
                    Undo.RecordObject(Target, "Rotate " + Target.name);
                    Target.rotation = Quaternion.Euler(rot);
                    HasChanged();
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Scale", GUILayout.Width(80));
                GUI.enabled = false;
                EditorGUILayout.Vector3Field("", Target.lossyScale);
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("LocalPosition", GUILayout.Width(80));
                Vector3 localpos = EditorGUILayout.Vector3Field("", Target.localPosition);
                if (localpos != Target.localPosition)
                {
                    Undo.RecordObject(Target, "Move " + Target.name);
                    Target.localPosition = localpos;
                    HasChanged();
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("LocalRotation", GUILayout.Width(80));
                Vector3 localrot = EditorGUILayout.Vector3Field("", Target.localRotation.eulerAngles);
                if (localrot != Target.localRotation.eulerAngles)
                {
                    Undo.RecordObject(Target, "Rotate " + Target.name);
                    Target.localRotation = Quaternion.Euler(localrot);
                    HasChanged();
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("LocalScale", GUILayout.Width(80));
                Vector3 localsca = EditorGUILayout.Vector3Field("", Target.localScale);
                if (localsca != Target.localScale)
                {
                    Undo.RecordObject(Target, "Scale " + Target.name);
                    Target.localScale = localsca;
                    HasChanged();
                }
                GUILayout.EndHorizontal();

                GUILayout.EndVertical();
            }
            #endregion

            #region Hierarchy
            GUILayout.BeginHorizontal("MeTransitionHead");
            GUILayout.Space(12);
            bool showHierarchy = EditorGUILayout.Foldout(_showHierarchy, "Hierarchy", true);
            if (showHierarchy != _showHierarchy)
            {
                _showHierarchy = showHierarchy;
                EditorPrefs.SetBool(EditorPrefsTable.Transform_Hierarchy, _showHierarchy);
            }
            GUILayout.EndHorizontal();

            if (_showHierarchy)
            {
                GUILayout.BeginVertical(EditorGlobalTools.Styles.Box);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Root: ", GUILayout.Width(80));
                EditorGUILayout.ObjectField(Target.root, typeof(Transform), true);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Parent: ", GUILayout.Width(80));
                GUI.color = Target.parent ? Color.white : Color.gray;
                _parent   = EditorGUILayout.ObjectField(Target.parent, typeof(Transform), true) as Transform;
                if (_parent != Target.parent)
                {
                    Undo.RecordObject(Target, "Change Parent " + Target.name);
                    Target.SetParent(_parent);
                    HasChanged();
                }
                GUI.color = Color.white;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Child Count: ", GUILayout.Width(80));
                GUILayout.Label(Target.childCount.ToString());
                GUILayout.FlexibleSpace();
                GUI.enabled = Target.childCount > 0;
                if (GUILayout.Button("Detach", "Minibutton"))
                {
                    if (EditorUtility.DisplayDialog("Prompt", "Are you sure you want to detach all children?", "Yes", "No"))
                    {
                        Undo.RecordObject(Target, "Detach Children");
                        Target.DetachChildren();
                        HasChanged();
                    }
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Expand Children", "MinibuttonLeft"))
                {
                    Type         type   = EditorGlobalTools.GetTypeInEditorAssemblies("UnityEditor.SceneHierarchyWindow");
                    EditorWindow window = EditorWindow.GetWindow(type);
                    MethodInfo   method = window.GetType().GetMethod("SetExpandedRecursive", BindingFlags.Public | BindingFlags.Instance);
                    int          id     = Target.gameObject.GetInstanceID();
                    method.Invoke(window, new object[] { id, true });
                }
                if (GUILayout.Button("Retract Children", "MinibuttonRight"))
                {
                    Type         type   = EditorGlobalTools.GetTypeInEditorAssemblies("UnityEditor.SceneHierarchyWindow");
                    EditorWindow window = EditorWindow.GetWindow(type);
                    MethodInfo   method = window.GetType().GetMethod("SetExpandedRecursive", BindingFlags.Public | BindingFlags.Instance);
                    int          id     = Target.gameObject.GetInstanceID();
                    method.Invoke(window, new object[] { id, false });
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Retract All", "Minibutton"))
                {
                    Type         type        = EditorGlobalTools.GetTypeInEditorAssemblies("UnityEditor.SceneHierarchyWindow");
                    EditorWindow window      = EditorWindow.GetWindow(type);
                    object       hierarchy   = window.GetType().GetProperty("sceneHierarchy", BindingFlags.Public | BindingFlags.Instance).GetValue(window);
                    int[]        expandedIDs = hierarchy.GetType().GetMethod("GetExpandedIDs", BindingFlags.Public | BindingFlags.Instance).Invoke(hierarchy, null) as int[];
                    MethodInfo   method      = hierarchy.GetType().GetMethod("ExpandTreeViewItem", BindingFlags.NonPublic | BindingFlags.Instance);
                    object[]     args        = new object[2];
                    args[1] = false;
                    for (int i = 0; i < expandedIDs.Length; i++)
                    {
                        args[0] = expandedIDs[i];
                        method.Invoke(hierarchy, args);
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.EndVertical();
            }
            #endregion

            #region Copy
            GUILayout.BeginHorizontal("MeTransitionHead");
            GUILayout.Space(12);
            bool showCopy = EditorGUILayout.Foldout(_showCopy, "Copy", true);
            if (showCopy != _showCopy)
            {
                _showCopy = showCopy;
                EditorPrefs.SetBool(EditorPrefsTable.Transform_Copy, _showCopy);
            }
            GUILayout.EndHorizontal();

            if (_showCopy)
            {
                GUILayout.BeginVertical(EditorGlobalTools.Styles.Box);

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Copy Position", EditorStyles.miniButtonLeft))
                {
                    GUIUtility.systemCopyBuffer = Target.position.ToCopyString("F4");
                    GlobalTools.LogInfo("已复制:" + GUIUtility.systemCopyBuffer);
                }
                if (GUILayout.Button("Copy LocalPosition", EditorStyles.miniButtonRight))
                {
                    GUIUtility.systemCopyBuffer = Target.localPosition.ToCopyString("F4");
                    GlobalTools.LogInfo("已复制:" + GUIUtility.systemCopyBuffer);
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Copy Rotation", EditorStyles.miniButtonLeft))
                {
                    if (_copyQuaternion)
                    {
                        GUIUtility.systemCopyBuffer = Target.rotation.ToCopyString("F4");
                        GlobalTools.LogInfo("已复制:" + GUIUtility.systemCopyBuffer);
                    }
                    else
                    {
                        string x = ClampAngle(Target.rotation.eulerAngles.x).ToString();
                        string y = ClampAngle(Target.rotation.eulerAngles.y).ToString();
                        string z = ClampAngle(Target.rotation.eulerAngles.z).ToString();

                        GUIUtility.systemCopyBuffer = x + "f," + y + "f," + z + "f";
                        GlobalTools.LogInfo("已复制:" + GUIUtility.systemCopyBuffer);
                    }
                }
                if (GUILayout.Button("Copy LocalRotation", EditorStyles.miniButtonRight))
                {
                    if (_copyQuaternion)
                    {
                        GUIUtility.systemCopyBuffer = Target.localRotation.ToCopyString("F4");
                        GlobalTools.LogInfo("已复制:" + GUIUtility.systemCopyBuffer);
                    }
                    else
                    {
                        string x = ClampAngle(Target.localRotation.eulerAngles.x).ToString();
                        string y = ClampAngle(Target.localRotation.eulerAngles.y).ToString();
                        string z = ClampAngle(Target.localRotation.eulerAngles.z).ToString();

                        GUIUtility.systemCopyBuffer = x + "f," + y + "f," + z + "f";
                        GlobalTools.LogInfo("已复制:" + GUIUtility.systemCopyBuffer);
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Copy Scale", EditorStyles.miniButton))
                {
                    GUIUtility.systemCopyBuffer = Target.localScale.ToCopyString("F4");
                    GlobalTools.LogInfo("已复制:" + GUIUtility.systemCopyBuffer);
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Copy Name", EditorStyles.miniButtonLeft))
                {
                    GUIUtility.systemCopyBuffer = Target.name;
                    GlobalTools.LogInfo("已复制:" + GUIUtility.systemCopyBuffer);
                }
                if (GUILayout.Button("Copy FullName", EditorStyles.miniButtonRight))
                {
                    GUIUtility.systemCopyBuffer = Target.FullName();
                    GlobalTools.LogInfo("已复制:" + GUIUtility.systemCopyBuffer);
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                _copyQuaternion = GUILayout.Toggle(_copyQuaternion, "Copy Quaternion");
                GUILayout.EndHorizontal();

                GUILayout.EndVertical();
            }
            #endregion
        }
Exemplo n.º 29
0
        private void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.HelpBox("设置Root及以下所有Graphic组件的Raycast Target属性", MessageType.Info);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Root:", GUILayout.Width(100));
            _root = EditorGUILayout.ObjectField(_root, typeof(GameObject), true) as GameObject;
            EditorGUILayout.EndHorizontal();

            GUI.enabled = _root;
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Text", GUILayout.Width(100));
            _text = GUILayout.Toggle(_text, "");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Image", GUILayout.Width(100));
            _image = GUILayout.Toggle(_image, "");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("RawImage", GUILayout.Width(100));
            _rawImage = GUILayout.Toggle(_rawImage, "");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Button", GUILayout.Width(100));
            _button = GUILayout.Toggle(_button, "");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Toggle", GUILayout.Width(100));
            _toggle = GUILayout.Toggle(_toggle, "");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Slider", GUILayout.Width(100));
            _slider = GUILayout.Toggle(_slider, "");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Scrollbar", GUILayout.Width(100));
            _scrollbar = GUILayout.Toggle(_scrollbar, "");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("InputField", GUILayout.Width(100));
            _inputField = GUILayout.Toggle(_inputField, "");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Set"))
            {
                Text[] ts = _root.GetComponentsInChildren <Text>(true);
                foreach (Text t in ts)
                {
                    t.raycastTarget = _text;
                }
                GlobalTools.LogInfo("[" + _root.name + "] Text设置完成!共设置了 " + ts.Length + " 处Raycast Target为" + _text + "!");

                Image[] ims = _root.GetComponentsInChildren <Image>(true);
                foreach (Image i in ims)
                {
                    i.raycastTarget = _image;
                }
                GlobalTools.LogInfo("[" + _root.name + "] Image设置完成!共设置了 " + ims.Length + " 处Raycast Target为" + _image + "!");

                RawImage[] ris = _root.GetComponentsInChildren <RawImage>(true);
                foreach (RawImage ri in ris)
                {
                    ri.raycastTarget = _rawImage;
                }
                GlobalTools.LogInfo("[" + _root.name + "] RawImage设置完成!共设置了 " + ris.Length + " 处Raycast Target为" + _rawImage + "!");

                Button[] bs = _root.GetComponentsInChildren <Button>(true);
                foreach (Button b in bs)
                {
                    if (b.targetGraphic)
                    {
                        b.targetGraphic.raycastTarget = _button;
                    }
                }
                GlobalTools.LogInfo("[" + _root.name + "] Button设置完成!共设置了 " + bs.Length + " 处Raycast Target为" + _button + "!");

                Toggle[] tos = _root.GetComponentsInChildren <Toggle>(true);
                foreach (Toggle t in tos)
                {
                    if (t.graphic)
                    {
                        t.graphic.raycastTarget = _toggle;
                    }
                }
                GlobalTools.LogInfo("[" + _root.name + "] Toggle设置完成!共设置了 " + tos.Length + " 处Raycast Target为" + _toggle + "!");

                Slider[] ss = _root.GetComponentsInChildren <Slider>(true);
                foreach (Slider t in ss)
                {
                    if (t.fillRect)
                    {
                        t.fillRect.GetComponent <Image>().raycastTarget = _slider;
                    }
                }
                GlobalTools.LogInfo("[" + _root.name + "] Slider设置完成!共设置了 " + ss.Length + " 处Raycast Target为" + _slider + "!");

                Scrollbar[] slls = _root.GetComponentsInChildren <Scrollbar>(true);
                foreach (Scrollbar s in slls)
                {
                    if (s.GetComponent <Image>())
                    {
                        s.GetComponent <Image>().raycastTarget = _scrollbar;
                    }
                    if (s.handleRect)
                    {
                        s.handleRect.GetComponent <Image>().raycastTarget = _scrollbar;
                    }
                }
                GlobalTools.LogInfo("[" + _root.name + "] Scrollbar设置完成!共设置了 " + slls.Length + " 处Raycast Target为" + _scrollbar + "!");

                InputField[] ifs = _root.GetComponentsInChildren <InputField>(true);
                foreach (InputField i in ifs)
                {
                    if (i.textComponent)
                    {
                        i.textComponent.raycastTarget = _inputField;
                    }
                }
                GlobalTools.LogInfo("[" + _root.name + "] InputField设置完成!共设置了 " + ifs.Length + " 处Raycast Target为" + _inputField + "!");
            }
            EditorGUILayout.EndHorizontal();
            GUI.enabled = true;
        }
Exemplo n.º 30
0
        protected override void OnInspectorDefaultGUI()
        {
            base.OnInspectorDefaultGUI();

            GUILayout.BeginHorizontal();
            EditorGUILayout.HelpBox("State Count:" + Target.StateNames.Count, MessageType.Info);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            Toggle(Target.IsAutoRegister, out Target.IsAutoRegister, "Auto Register");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Name: ");
            TextField(Target.Name, out Target.Name);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Data: ");
            if (GUILayout.Button(Target.Data, "MiniPopup"))
            {
                GenericMenu gm    = new GenericMenu();
                List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies();
                gm.AddItem(new GUIContent("<None>"), Target.Data == "<None>", () =>
                {
                    Undo.RecordObject(target, "Set FSM Data Class");
                    Target.Data = "<None>";
                    HasChanged();
                });
                for (int i = 0; i < types.Count; i++)
                {
                    if (types[i].IsSubclassOf(typeof(FSMData)))
                    {
                        int j = i;
                        gm.AddItem(new GUIContent(types[j].FullName), Target.Data == types[j].FullName, () =>
                        {
                            Undo.RecordObject(target, "Set FSM Data Class");
                            Target.Data = types[j].FullName;
                            HasChanged();
                        });
                    }
                }
                gm.ShowAsContext();
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUI.enabled = Target.DefaultStateName != "";
            GUILayout.Label("Default: " + Target.DefaultStateName);
            GUI.enabled = true;
            GUILayout.FlexibleSpace();
            GUI.enabled = Target.StateNames.Count > 0;
            if (GUILayout.Button("Set Default", "MiniPopup"))
            {
                GenericMenu gm = new GenericMenu();
                for (int i = 0; i < Target.StateNames.Count; i++)
                {
                    int j = i;
                    gm.AddItem(new GUIContent(Target.StateNames[j]), Target.DefaultStateName == Target.StateNames[j], () =>
                    {
                        Undo.RecordObject(target, "Set FSM Default State");
                        Target.DefaultState     = Target.States[j];
                        Target.DefaultStateName = Target.StateNames[j];
                        HasChanged();
                    });
                }
                gm.ShowAsContext();
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();

            for (int i = 0; i < Target.StateNames.Count; i++)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(string.Format("{0}.{1}", i + 1, Target.StateNames[i]));
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Edit", "minibuttonleft"))
                {
                    if (_stateTypes.ContainsKey(Target.States[i]))
                    {
                        UnityEngine.Object classFile = AssetDatabase.LoadAssetAtPath(_stateTypes[Target.States[i]], typeof(TextAsset));
                        if (classFile)
                        {
                            AssetDatabase.OpenAsset(classFile);
                        }
                        else
                        {
                            GlobalTools.LogError("没有找到 " + Target.States[i] + " 脚本文件!");
                        }
                    }
                    else
                    {
                        GlobalTools.LogError("没有找到 " + Target.States[i] + " 脚本文件!");
                    }
                }
                if (GUILayout.Button("Delete", "minibuttonright"))
                {
                    Undo.RecordObject(target, "Delete FSM State");
                    if (Target.DefaultStateName == Target.StateNames[i])
                    {
                        Target.DefaultState     = "";
                        Target.DefaultStateName = "";
                    }

                    Target.States.RemoveAt(i);
                    Target.StateNames.RemoveAt(i);

                    if (Target.DefaultStateName == "" && Target.StateNames.Count > 0)
                    {
                        Target.DefaultState     = Target.States[0];
                        Target.DefaultStateName = Target.StateNames[0];
                    }
                    HasChanged();
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Add State", "MiniPopup"))
            {
                GenericMenu gm    = new GenericMenu();
                List <Type> types = GlobalTools.GetTypesInRunTimeAssemblies();
                for (int i = 0; i < types.Count; i++)
                {
                    if (types[i].IsSubclassOf(typeof(FiniteState)))
                    {
                        int    j         = i;
                        string stateName = types[j].FullName;
                        FiniteStateNameAttribute fsmAtt = types[j].GetCustomAttribute <FiniteStateNameAttribute>();
                        if (fsmAtt != null)
                        {
                            stateName = fsmAtt.Name;
                        }

                        if (Target.States.Contains(types[j].FullName))
                        {
                            gm.AddDisabledItem(new GUIContent(stateName));
                        }
                        else
                        {
                            gm.AddItem(new GUIContent(stateName), false, () =>
                            {
                                Undo.RecordObject(target, "Add FSM State");
                                Target.States.Add(types[j].FullName);
                                Target.StateNames.Add(stateName);

                                if (Target.DefaultStateName == "")
                                {
                                    Target.DefaultState     = Target.States[0];
                                    Target.DefaultStateName = Target.StateNames[0];
                                }
                                HasChanged();
                            });
                        }
                    }
                }
                gm.ShowAsContext();
            }
            GUILayout.EndHorizontal();
        }