示例#1
0
        private static GameObject CreateLogObstacle()
        {
            GameObject root = new GameObject();

            root.name = "LogObstacle";
            var chainCreator = root.AddComponent <Core.EditorTools.ObstaclesTools.ChainCreator>();

            chainCreator.ObstacleMounts = new System.Collections.Generic.List <GameObject>();
            chainCreator.WallMounts     = new System.Collections.Generic.List <GameObject>();
            chainCreator.Chains         = new System.Collections.Generic.List <GameObject>();
            //Instantiate prefabs
            GameObject logObj = GameObject.Instantiate(BuilderProperties.LogPrefab);

            chainCreator.Log = logObj;
            Log logScript = logObj.GetComponent <Log>();

            logObj.transform.SetParent(root.transform);
            GameObject[] chains = new GameObject[logScript.DefaultMounts.Length];
            GameObject[] mounts = new GameObject[logScript.DefaultMounts.Length];
            for (int i = 0; i < logScript.DefaultMounts.Length; i++)
            {
                mounts[i]      = GameObject.Instantiate(BuilderProperties.MountPrefab);
                mounts[i].name = "Mount" + (i + 1).ToString();
                mounts[i].transform.position += Vector3.right * 2f * i;
                mounts[i].transform.SetParent(root.transform);

                chains[i]      = new GameObject();
                chains[i].name = "Chain" + (i + 1).ToString();
                CreateLogChain(chains[i], mounts[i], logScript.DefaultMounts[i].gameObject);
                chains[i].transform.SetParent(root.transform);

                chainCreator.ObstacleMounts.Add(logScript.DefaultMounts[i].gameObject);
                chainCreator.WallMounts.Add(mounts[i]);
                chainCreator.Chains.Add(chains[i]);
            }
            _TouchEventManager = null;
            return(root);
        }
示例#2
0
        public static void  CreateLogChain(GameObject targetRoot, GameObject beginMount, GameObject endMount)
        {
            _TouchEventManager = MonoBehaviour.FindObjectOfType(typeof(Core.Events.TouchEventsManager)) as Core.Events.TouchEventsManager;
            if (_TouchEventManager == null)
            {
                Debug.Log("На сцене нет event manager. Верните!");
                return;
            }
            Vector3 chainBegin = beginMount.transform.position +
                                 Vector3.down * BuilderProperties.MOUNT_JOINT_ANCOR_Y + Vector3.left * BuilderProperties.MOUNT_JOINT_ANCOR_X,
                    chainEnd = endMount.transform.position +
                               Vector3.up * BuilderProperties.MOUNT_JOINT_ANCOR_Y + Vector3.left * BuilderProperties.MOUNT_JOINT_ANCOR_X;

            BuildChain(targetRoot, CalcChainLength(chainBegin, chainEnd), CalcChainAngle(chainBegin, chainEnd));

            var chain = targetRoot.GetComponent <Chain>();

            AttachChain(chain, beginMount, endMount);
            chain.BeginMount = beginMount;
            chain.EndMount   = endMount;

            targetRoot.transform.position = beginMount.transform.position - Vector3.up
                                            * BuilderProperties.MOUNT_JOINT_ANCOR_Y - Vector3.right * BuilderProperties.MOUNT_JOINT_ANCOR_X;
        }