Пример #1
0
        /// <summary>
        /// Actor 出生
        /// </summary>
        /// <param name="point"></param>
        /// <param name="actorArt"></param>
        protected virtual void Born(LevelPoint point, string actorArt)
        {
            // 创建角色
            GameObject prefab  = LevelAsset.GetGameObject(actorArt);
            var        actorGo = GameObject.Instantiate <GameObject>(prefab);

            actorGo.transform.parent = transform;
            actorGameObject          = actorGo.GetComponent <ActorGameObject>();

            // 组件获取
            m_animator     = actorGameObject.GetComponent <Animator>();
            m_rigidbody    = actorGameObject.GetComponent <Rigidbody>();
            m_navMeshAgent = actorGameObject.GetComponent <NavMeshAgent>();

            // 基础设置
            actorGameObject.actor = this;
            actorGameObject.transform.position         = point.position;
            actorGameObject.transform.localEulerAngles = point.rotationAngle;

            // 寻路设置
            m_navMeshAgent.speed = attribute.GetAttribute(ActorAttributeType.MoveSpeed);

            m_moveVt = Vector3.zero;
            m_dirVt  = actorGameObject.transform.forward;
        }
Пример #2
0
        public override void Born(LevelPoint point)
        {
            base.Born(point, m_dataCSV.art);

            // 怪行为设置
            m_behaviorTree = actorGameObject.gameObject.AddComponent <BehaviorTree>();
            m_behaviorTree.StartWhenEnabled    = false;
            m_behaviorTree.RestartWhenComplete = true;
            m_behaviorTree.ExternalBehavior    = LevelAsset.GetExternalBehaviorTree(m_dataCSV.behavior);
            m_behaviorTree.SetVariableValue("Target", Game.hero.actorGameObject.gameObject.transform);
            m_behaviorTree.EnableBehavior();
        }
Пример #3
0
        public void LoadAsset(bool isShow = true)
        {
            var prefab = LevelAsset.GetGameObject(bundleName, assetName);

            m_gridGameObject                 = GameObject.Instantiate <GameObject>(prefab);
            m_gridTransform                  = m_gridGameObject.transform;
            m_gridTransform.position         = position;
            m_gridTransform.parent           = transform;
            m_gridTransform.localEulerAngles = rotationAngle;
            m_gridGameObject.AddComponent <BoxCollider>();
            gameObject.GetComponentInChildren <MeshRenderer>().enabled = isShow;
            animation = m_gridGameObject.AddComponent <LevelGridAnimation>();

            GameUtils.SetGameObjectLayer(m_gridGameObject, layer);
        }
Пример #4
0
        /// <summary>
        /// poolContainer 获取对象
        /// </summary>
        /// <param name="containerId">对象池容器id(资源路径)</param>
        /// <param name="parent"></param>
        /// <param name="position"></param>
        /// <param name="rotation"></param>
        public GameObject Spawn(string containerId, Transform parent = null, Vector3 position = new Vector3(), Quaternion rotation = new Quaternion())
        {
            if (pools.ContainsKey(containerId))
            {
                return(pools[containerId].Spawn(parent, position, rotation));
            }

            var prefab = LevelAsset.GetGameObject(containerId);

            if (prefab != null)
            {
                return(CreatePoolContainer(containerId, prefab).Spawn(parent, position, rotation));
            }
            Debug.LogError("Game pool spawn gameObject null! [ " + containerId + "]");
            return(null);
        }
Пример #5
0
        /// <summary>
        /// 创建物体
        /// </summary>
        /// <param name="prefabName">prefab name</param>
        protected void Create(string prefabName)
        {
            string bundleName = "uiprefabs/" + prefabName.ToLower();
            string assetName  = prefabName + ".prefab";
            var    prefab     = LevelAsset.GetGameObject(bundleName, assetName);

            gameObject = GameObject.Instantiate <GameObject>(prefab);
            transform  = gameObject.transform;
            panel      = gameObject.GetComponentInChildren <UIPanel>();
            ui         = panel.ui;

            Game.mainGame.OnUpdate -= OnUpdate;
            Game.mainGame.OnUpdate += OnUpdate;

            Game.mainGame.OnLateUpdate -= OnLateUpdate;
            Game.mainGame.OnLateUpdate += OnLateUpdate;

            OnInitialize();
        }