Ejemplo n.º 1
0
        public static void SetTransformToSceneEntryPoint(Transform transformToMove, int entryPointNumber = 0)
        {
            if (transformToMove == null)
            {
                Debug.LogError("Cant move a null game object.");
                return;
            }

            Transform targetEntryPointTransform = CSceneEntryPoint.GetSceneEntryPointTransform(entryPointNumber);

            var offset = new Vector3(0f, 0.001f, 0f);

            if (targetEntryPointTransform == null)
            {
                transformToMove.position = Vector3.zero + offset;
                transformToMove.rotation = Quaternion.identity;
            }
            else
            {
                var character = transformToMove.GetComponent <CCharacterBase>();
                if (character != null)
                {
                    character.TeleportToLocation(targetEntryPointTransform.position, targetEntryPointTransform.rotation);
                }
                else
                {
                    transformToMove.position = targetEntryPointTransform.position + offset;
                    transformToMove.rotation = targetEntryPointTransform.rotation;
                }
            }

            Debug.Log($"Moving {transformToMove.name} to {nameof(entryPointNumber)}:'{entryPointNumber}' at position {transformToMove.position}", targetEntryPointTransform);
        }
Ejemplo n.º 2
0
        public CCharacterBase InstantiateAndAssignCharacter(string key)
        {
            if (key.CIsNullOrEmpty())
            {
                Debug.LogWarning($"Created player {this.PlayerNumber} with no controlling character because '{nameof(key)}' is null or its RuntimeKey is invalid.");
                return(null);
            }

            var character = CAssets.LoadAndInstantiate <CCharacterBase>(key);

            if (character == null)
            {
                Debug.LogError($"Asset key '{key}' gameobject doesnt have a {nameof(CCharacterBase)} component on it! could not create player!");
                return(null);
            }

            var entryPoint = CSceneEntryPoint.GetSceneEntryPointTransform(0);

            if (entryPoint != null)
            {
                Debug.Log($"Setting '{character.name}' to entryPoint number'{0}'", entryPoint.gameObject);
                character.TeleportToLocation(entryPoint.transform.position, entryPoint.transform.rotation);
                Physics.SyncTransforms();
            }
            character.gameObject.SetActive(false);
            character.name = $"[Character] {character.name}";

            this.AddControllingCharacter(character);
            character.gameObject.SetActive(true);

            this.CheckIfNeedToCreateCamera();

            Debug.Log($"Created player {this.PlayerNumber} controlling character '{character.name}'.", character);

            return(character);
        }