private void EnableAI()
 {
     if (m_lstTargetObjects == null || m_lstTargetObjects.Count <= 0)
     {
         return;
     }
     foreach (GameObject charObject in m_lstTargetObjects)
     {
         CharTransformContainer container = charObject.GetComponent <CharTransformContainer>();
         if (container == null)
         {
             Debuger.LogError("No Container in " + charObject.ToString());
             return;
         }
         Npc npc = null;
         if (container.GetData() is Npc)
         {
             npc = (Npc)container.GetData();
         }
         if (null != npc)
         {
             npc.SetAIStatus(true);
             npc.IsPlayerControlled = false;
             npc.ResetGroup();
         }
     }
 }
Esempio n. 2
0
 private void MoveNpc()
 {
     if (m_lstTargetObjects == null || m_lstTargetObjects.Count <= 0)
     {
         Debuger.LogWarning("No Exist Npc !");
         return;
     }
     foreach (GameObject charObject in m_lstTargetObjects)
     {
         CharTransformContainer container = charObject.GetComponent <CharTransformContainer>();
         if (container == null)
         {
             Debuger.LogError("No Container in " + charObject.ToString());
             return;
         }
         m_Npc = (Npc)container.GetData();
         List <CharMovement> movePath = new List <CharMovement>();
         foreach (var point in m_Config.LstSpeedMove)
         {
             //Vector3 point = target.Target.GetVector3();
             //movePath.Add(point);
             CharMovement move = new CharMovement();
             move.Target = point.Target.GetVector3();
             move.Speed  = (float)point.Speed;
             movePath.Add(move);
         }
         Rigidbody body = charObject.GetComponent <Rigidbody>();
         if (body)
         {
             m_bIsKinematic   = body.isKinematic;
             body.isKinematic = true;
         }
         m_Npc.MovePath(movePath);
     }
 }
    virtual public void Initialize(Ilife lifeData, string resourcePath, AssetType resourceType)
    {
        m_LifeData = lifeData;
        m_iInstanceId = lifeData.GetInstanceId();

        m_ObjectInstance = GameObject.Instantiate(ResourceManager.Instance.LoadBuildInResource<GameObject>(resourcePath, resourceType));

        //load material
        string localpath = resourcePath.Substring(0, resourcePath.LastIndexOf('/'));
        m_NormalMaterial = ResourceManager.Instance.LoadBuildInResource<Material>(localpath + "/Normal", AssetType.Char);
        m_HighlightMaterial = ResourceManager.Instance.LoadBuildInResource<Material>(localpath + "/SelectedHighlight", AssetType.Char);
        m_MeshRender = ComponentTool.FindChildComponent<SkinnedMeshRenderer>("Body", m_ObjectInstance);
        if (null == m_NormalMaterial || null == m_HighlightMaterial || null == m_MeshRender)
        {
            Debuger.LogWarning("can't load mesh render or normal&highlight materials !");
        }

        //mark transform
        m_CharContainer = m_ObjectInstance.AddComponent<CharTransformContainer>();
        m_CharContainer.Initialize(lifeData.GetInstanceId(), lifeData);

        if (null == m_ObjectInstance)
        {
            Debuger.LogError("Can't load resource " + resourcePath);
        }
        m_AnimatorAgent = new AnimatorAgent(m_ObjectInstance);
    }
Esempio n. 4
0
 private void DisableAI()
 {
     if (m_mapTargetObjects == null || m_mapTargetObjects.Count <= 0)
     {
         return;
     }
     foreach (GameObject charObject in m_mapTargetObjects.Values)
     {
         CharTransformContainer container = charObject.GetComponent <CharTransformContainer>();
         if (container == null)
         {
             Debuger.LogError("No Container in " + charObject.ToString());
             return;
         }
         Npc npc = null;
         if (container.GetData() is Npc)
         {
             npc = (Npc)container.GetData();
         }
         if (null != npc)
         {
             npc.SetAIStatus(false);
         }
     }
 }
    virtual public void Initialize(Ilife lifeData, string resourcePath, AssetType resourceType)
    {
        m_LifeData    = lifeData;
        m_iInstanceId = lifeData.GetInstanceId();

        m_ObjectInstance = GameObject.Instantiate(ResourceManager.Instance.LoadBuildInResource <GameObject>(resourcePath, resourceType));

        //load material
        string localpath = resourcePath.Substring(0, resourcePath.LastIndexOf('/'));

        m_NormalMaterial    = ResourceManager.Instance.LoadBuildInResource <Material>(localpath + "/Normal", AssetType.Char);
        m_HighlightMaterial = ResourceManager.Instance.LoadBuildInResource <Material>(localpath + "/SelectedHighlight", AssetType.Char);
        m_MeshRender        = ComponentTool.FindChildComponent <SkinnedMeshRenderer>("Body", m_ObjectInstance);
        if (null == m_NormalMaterial || null == m_HighlightMaterial || null == m_MeshRender)
        {
            Debuger.LogWarning("can't load mesh render or normal&highlight materials !");
        }

        //mark transform
        m_CharContainer = m_ObjectInstance.AddComponent <CharTransformContainer>();
        m_CharContainer.Initialize(lifeData.GetInstanceId(), lifeData);

        if (null == m_ObjectInstance)
        {
            Debuger.LogError("Can't load resource " + resourcePath);
        }
        m_AnimatorAgent = new AnimatorAgent(m_ObjectInstance);
    }
Esempio n. 6
0
 private void AddAffectedObject(GameObject obj, CharTransformContainer objContainer)
 {
     if (m_mapTargetObjects.ContainsKey(objContainer.GetId()))
     {
         Debuger.LogWarning("Instance: '" + obj.name + "' ID: " + objContainer.GetId().ToString() + " Already Exist");
     }
     else
     {
         m_mapTargetObjects.Add(objContainer.GetId(), obj);
         Debuger.Log("AffectedObject Add: " + objContainer.GetId().ToString());
     }
 }
Esempio n. 7
0
 public void InsertGeneratedObjects(Dictionary <int, GameObject> generatedObjects)
 {
     foreach (int index in generatedObjects.Keys)
     {
         CharTransformContainer objContainer = generatedObjects[index].GetComponent <CharTransformContainer>();
         if (objContainer == null)
         {
             Debuger.LogWarning("Generated Container Not Found in " + generatedObjects[index].name + " ,ID: " + index.ToString());
             continue;
         }
         else
         {
             AddGeneratedObject(generatedObjects[index], index);
         }
     }
 }
Esempio n. 8
0
 private void MoveNpc()
 {
     if (m_lstTargetObjects == null || m_lstTargetObjects.Count <= 0)
     {
         Debuger.LogWarning("No Exist Npc !");
         return;
     }
     foreach (GameObject charObject in m_lstTargetObjects)
     {
         CharTransformContainer container = charObject.GetComponent <CharTransformContainer>();
         if (container == null)
         {
             Debuger.LogError("No Container in " + charObject.ToString());
             return;
         }
         m_Npc = (Npc)container.GetData();
         m_Npc.Rotate((float)m_Config.Rotation);
     }
 }
Esempio n. 9
0
    public ActionPlayer(int iActionId, ActionFileData data, ActionParam param, List <GameObject> affectedObjects = null)
    {
        //Check
        if (null == data)
        {
            return;
        }
        m_AffectedObject = affectedObjects;

        //Save Init Info
        SaveInitInfo();
        //Set Data
        m_ActionId       = iActionId;
        m_ActionFileData = data;
        m_nInstanceID    = AllocInstanceId();
        m_ActionParam    = param;
        if (affectedObjects != null && affectedObjects.Count > 0)
        {
            //Add Target
            foreach (GameObject obj in affectedObjects)
            {
                if (obj == null)
                {
                    Debuger.LogWarning("None(GameObject) in TargetObjectList");
                    continue;
                }
                CharTransformContainer objContainer = obj.GetComponent <CharTransformContainer>();
                if (objContainer == null)
                {
                    Debuger.LogWarning("Instance Container Not Found in " + obj.name);
                    continue;
                }
                else
                {
                    AddAffectedObject(obj, objContainer);
                }
                //disable rigidbody
                SetPhysicStatus(obj, false);
            }
        }
        Reset();
    }
 private void StopMove()
 {
     // stop npcs
     if (m_lstTargetObjects == null || m_lstTargetObjects.Count <= 0)
     {
         return;
     }
     foreach (GameObject obj in m_lstTargetObjects)
     {
         CharTransformContainer container = obj.GetComponent <CharTransformContainer>();
         if (container != null)
         {
             if (container.GetData() is Npc)
             {
                 Npc npc = (Npc)container.GetData();
                 npc.StopMove();
             }
         }
     }
 }
Esempio n. 11
0
    private void OnSelectNpc(Gesture gesture)
    {
        if (!(gesture is LongPressGesture))
        {
            return;
        }

        if (!m_bIsDictate)
        {
            return;
        }

        LongPressGesture longGest = (LongPressGesture)gesture;

        // Set npc selected
        GameObject selection = gesture.Selection;

        if (null == selection)
        {
            return;
        }
        CharTransformContainer container = selection.GetComponent <CharTransformContainer>();

        if (container == null)
        {
            //Debug.LogWarning("container not found");
            return;
        }
        var data = container.GetData();

        if (data is Npc)
        {
            Npc npc = (Npc)data;
            if (npc.IsInGroup)
            {
                CharTransformData charData = (CharTransformData)(npc.GetTransformData());
                charData.SetSelectedStatus(true);
            }
        }
    }
Esempio n. 12
0
 private void AddAffectedObject(GameObject obj, CharTransformContainer objContainer)
 {
     if (m_mapTargetObjects.ContainsKey(objContainer.GetId()))
     {
         Debuger.LogWarning("Instance: '" + obj.name + "' ID: " + objContainer.GetId().ToString() + " Already Exist");
     }
     else
     {
         m_mapTargetObjects.Add(objContainer.GetId(), obj);
         Debuger.Log("AffectedObject Add: " + objContainer.GetId().ToString());
     }
 }
Esempio n. 13
0
    private void OnCharMove(Gesture gesture)
    {
        // check gesture
        if (!(gesture is DragGesture))
        {
            return;
        }
        DragGesture dragGest = (DragGesture)gesture;

        // Start
        if (dragGest.Phase == ContinuousGesturePhase.Started)
        {
            m_CurrentSelection = gesture.Selection;
            if (null == gesture.Selection)
            {
                return;
            }
            Transform transform = null;
            if (GetMouseHitPlayer(out transform))
            {
                gesture.Selection  = transform.gameObject;
                m_CurrentSelection = gesture.Selection;
            }
            // get char
            CharTransformContainer container = m_CurrentSelection.GetComponent <CharTransformContainer>();
            if (container == null)
            {
                //Debug.LogWarning("container not found");
                return;
            }
            var data = container.GetData();
            // player
            if (data is PlayerCharacter)
            {
                m_Player = (PlayerCharacter)data;
                CharTransformData charData = (CharTransformData)(m_Player.GetTransformData());

                m_DraggingFinger = gesture.Fingers[0];
                CreateLineRender();
            }
            // npc
            else if (data is Npc)
            {
                Npc npc = (Npc)data;
                CharTransformData charData = (CharTransformData)(npc.GetTransformData());
                // check npc selected
                if (charData.GetSelectedStatus())
                {
                    m_DraggingFinger = gesture.Fingers[0];
                    CreateLineRender();
                }
            }
        }
        // Update
        else if (dragGest.Phase == ContinuousGesturePhase.Updated)
        {
            // make sure this is the finger we started dragging with
            if (gesture.Fingers[0] != m_DraggingFinger)
            {
                return;
            }
            if (!m_CurrentSelection)
            {
                return;
            }
            if (m_LineRenderInstances.ContainsKey(m_CurrentSelection))
            {
                GameObject   lineRenderer = m_LineRenderInstances[m_CurrentSelection];
                LineRenderer renderer     = lineRenderer.GetComponent <LineRenderer>();
                if (renderer)
                {
                    renderer.SetPosition(0, m_CurrentSelection.transform.position);
                    Vector3 hitpoint = new Vector3();
                    if (GetMouseHitTerrainPos(out hitpoint))
                    {
                        renderer.SetPosition(1, hitpoint);
                        if (GestureManager.CheckNavmeshPoint(hitpoint))
                        {
                            renderer.SetColors(new Color(0, 1, 0), new Color(0, 1, 0));
                        }
                        else
                        {
                            renderer.SetColors(new Color(1, 0, 0), new Color(1, 0, 0));
                        }
                    }
                }
            }
        }
        // End
        else if (dragGest.Phase == ContinuousGesturePhase.Ended)
        {
            if (!m_CurrentSelection)
            {
                return;
            }

            ClearLineRender();

            // get char
            CharTransformContainer container = m_CurrentSelection.GetComponent <CharTransformContainer>();
            if (container == null)
            {
                //Debug.LogWarning("container not found");
                return;
            }
            var data = container.GetData();
            // player
            if (data is PlayerCharacter)
            {
                m_Player = (PlayerCharacter)data;
                MovePlayer();
            }
            // npc
            else if (data is Npc)
            {
                Npc npc = (Npc)data;
                CharTransformData charData = (CharTransformData)(npc.GetTransformData());
                if (charData.GetSelectedStatus())
                {
                    MoveNpc(npc);
                }
            }
        }
    }