private void Finish() { bool is2D = false; GameObject newCharacterOb = baseObject; GameObject newBaseObject = baseObject; if (IsFirstPerson()) { newBaseObject = new GameObject("Player"); newBaseObject.AddComponent <Paths>(); newBaseObject.AddComponent <Rigidbody>(); Player playerScript = newBaseObject.AddComponent <Player>(); playerScript.animationEngine = animationEngine; newBaseObject.tag = Tags.player; CapsuleCollider capsuleCollider = newBaseObject.AddComponent <CapsuleCollider>(); capsuleCollider.center = new Vector3(0f, 1f, 0f); capsuleCollider.height = 2f; GameObject cameraObject = new GameObject("First person camera"); cameraObject.transform.parent = newBaseObject.transform; cameraObject.transform.position = new Vector3(0f, 1.5f, 0f); Camera cam = cameraObject.AddComponent <Camera>(); cam.enabled = false; cameraObject.AddComponent <FirstPersonCamera>(); return; } if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity || animationEngine == AnimationEngine.SpritesUnityComplex) { string _name = charName; if (charName == null || charName.Length == 0) { _name = ("My new " + charType.ToString()); } if (!enforce3D) { is2D = true; FollowSortingMap followSortingMap = newCharacterOb.AddComponent <FollowSortingMap>(); followSortingMap.followSortingMap = true; } newBaseObject = new GameObject(_name); newCharacterOb.transform.parent = newBaseObject.transform; newCharacterOb.transform.position = Vector3.zero; newCharacterOb.transform.eulerAngles = Vector3.zero; } if (animationEngine == AnimationEngine.Mecanim || animationEngine == AnimationEngine.SpritesUnity || animationEngine == AnimationEngine.SpritesUnityComplex) { if (newCharacterOb.GetComponent <Animator>() == null) { newCharacterOb.AddComponent <Animator>(); } } else if (animationEngine == AnimationEngine.Legacy) { if (newCharacterOb.GetComponent <Animation>() == null) { newCharacterOb.AddComponent <Animation>(); } } if (newBaseObject.GetComponent <AudioSource>() == null) { newBaseObject.AddComponent <AudioSource>(); } if (newBaseObject.GetComponent <Paths>() == null) { newBaseObject.AddComponent <Paths>(); } AC.Char charScript = null; if (charType == CharType.Player) { charScript = newBaseObject.AddComponent <Player>(); newBaseObject.tag = Tags.player; } else { charScript = newBaseObject.AddComponent <NPC>(); if (is2D) { BoxCollider2D boxCollider = newCharacterOb.AddComponent <BoxCollider2D>(); UnityVersionHandler.SetBoxCollider2DCentre(boxCollider, new Vector2(0f, 1f)); boxCollider.size = new Vector2(1f, 2f); boxCollider.isTrigger = true; } else { CapsuleCollider capsuleCollider = newCharacterOb.AddComponent <CapsuleCollider>(); capsuleCollider.center = new Vector3(0f, 1f, 0f); capsuleCollider.height = 2f; } newCharacterOb.AddComponent <Hotspot>(); if (is2D) { newCharacterOb.GetComponent <Hotspot>().drawGizmos = false; } } if (is2D) { newBaseObject.AddComponent <CircleCollider2D>(); if (charType == CharType.Player) { if (newBaseObject.GetComponent <Rigidbody2D>() == null) { newBaseObject.AddComponent <Rigidbody2D>(); } charScript.ignoreGravity = true; } } else { if (newBaseObject.GetComponent <Rigidbody>() == null) { newBaseObject.AddComponent <Rigidbody>(); } if (charType == CharType.Player) { CapsuleCollider capsuleCollider = newBaseObject.AddComponent <CapsuleCollider>(); capsuleCollider.center = new Vector3(0f, 1f, 0f); capsuleCollider.height = 2f; } } if (animationEngine == AnimationEngine.Sprites2DToolkit || animationEngine == AnimationEngine.SpritesUnity || animationEngine == AnimationEngine.SpritesUnityComplex) { charScript.spriteChild = newCharacterOb.transform; } if (charType == CharType.Player && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.hotspotDetection == HotspotDetection.PlayerVicinity) { GameObject detectorOb = new GameObject("HotspotDetector"); detectorOb.transform.parent = newBaseObject.transform; detectorOb.transform.position = Vector3.zero; detectorOb.AddComponent <DetectHotspots>(); if (is2D) { CircleCollider2D circleCollider = detectorOb.AddComponent <CircleCollider2D>(); circleCollider.isTrigger = true; } else { SphereCollider sphereCollider = detectorOb.AddComponent <SphereCollider>(); sphereCollider.isTrigger = true; } } charScript.animationEngine = animationEngine; if (animationEngine == AC.AnimationEngine.Custom) { charScript.customAnimationClass = customAnimationClass; } charScript.speechLabel = charName; GameObject soundChild = new GameObject("Sound child"); soundChild.transform.parent = newBaseObject.transform; soundChild.AddComponent <AudioSource>(); Sound sound = soundChild.AddComponent <Sound>(); charScript.soundChild = sound; baseObject = null; charName = ""; EditorGUIUtility.PingObject(newBaseObject); }
public override string ToString() { return(CharType.ToString() + ": " + Range.First.ToString() + " - " + Range.Length.ToString()); }