Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 43.39 KB | None | 0 0
  1. using UnityEngine;
  2. using KBEngine;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Threading;
  7.  
  8. public class selavatar_ui : MonoBehaviour {
  9.     public static bool started = false;
  10.     public static int windowsize = 0;
  11.     public static string currsel_item = "item1";
  12.     public static string currsel_selListItem = "sel_list_item_focus1";
  13.     public static bool isCreateMode = false;
  14.     private static bool[] showAvatars = new bool[3]{false, false, false};
  15.     private static string[] avatarnames = new string[]{"德古拉", "狼骑", "血精灵", "萨满", "尖刺兽", "暗影"};
  16.     public static Byte changeAvatarItem = 0;
  17.     public static UILabel log_label = null;
  18.     public static UILabel loadAvatar_label = null;
  19.    
  20.     public struct AvatarInfo
  21.     {
  22.         public UInt16 level;
  23.         public string name;
  24.         public Byte roleType;
  25.         public UInt64 dbid;
  26.     }
  27.    
  28.     private static List<AvatarInfo> avatarList = new List<AvatarInfo>();
  29.    
  30.     void reset()
  31.     {
  32.         windowsize = 0;
  33.         currsel_item = "item1";
  34.         currsel_selListItem = "sel_list_item_focus1";
  35.         isCreateMode = false;
  36.     }
  37.    
  38.     void Awake ()    
  39.     {
  40.         log_label = UnityEngine.GameObject.Find("log_label").GetComponent<UILabel>();
  41.         loadAvatar_label = UnityEngine.GameObject.Find("loadAvatar_label").GetComponent<UILabel>();
  42.        
  43.         //autoSetPosition();
  44.        
  45.         UnityEngine.GameObject avataritem1_focus_trigger = UnityEngine.GameObject.Find("item1_focus");
  46.         UnityEngine.GameObject avataritem2_focus_trigger = UnityEngine.GameObject.Find("item2_focus");
  47.         UnityEngine.GameObject avataritem3_focus_trigger = UnityEngine.GameObject.Find("item3_focus");
  48.         UnityEngine.GameObject avataritem4_focus_trigger = UnityEngine.GameObject.Find("item4_focus");
  49.         UnityEngine.GameObject avataritem5_focus_trigger = UnityEngine.GameObject.Find("item5_focus");
  50.         UnityEngine.GameObject avataritem6_focus_trigger = UnityEngine.GameObject.Find("item6_focus");
  51.        
  52.         UnityEngine.GameObject skillitem1_focus_trigger = UnityEngine.GameObject.Find("skill_item1_focus");
  53.         UnityEngine.GameObject skillitem2_focus_trigger = UnityEngine.GameObject.Find("skill_item2_focus");
  54.         UnityEngine.GameObject skillitem3_focus_trigger = UnityEngine.GameObject.Find("skill_item3_focus");
  55.        
  56.         UnityEngine.GameObject createAvatarButton = UnityEngine.GameObject.Find("createAvatarButton");
  57.         UnityEngine.GameObject removeAvatarButton = UnityEngine.GameObject.Find("removeAvatarButton");
  58.         UnityEngine.GameObject backbtn = UnityEngine.GameObject.Find("back");
  59.         UnityEngine.GameObject entergame = UnityEngine.GameObject.Find("entergame");
  60.         UnityEngine.GameObject goto_createavatarmode = UnityEngine.GameObject.Find("goto_createavatarmode");
  61.        
  62.         UnityEngine.GameObject sel_list_item_focus1 = UnityEngine.GameObject.Find("sel_list_item_focus1");
  63.         UnityEngine.GameObject sel_list_item_focus2 = UnityEngine.GameObject.Find("sel_list_item_focus2");
  64.         UnityEngine.GameObject sel_list_item_focus3 = UnityEngine.GameObject.Find("sel_list_item_focus3");
  65.        
  66.         UnityEngine.GameObject fuse_left = UnityEngine.GameObject.Find("fuse_left");
  67.         UnityEngine.GameObject fuse_right = UnityEngine.GameObject.Find("fuse_right");
  68.         UnityEngine.GameObject lianxing_left = UnityEngine.GameObject.Find("lianxing_left");
  69.         UnityEngine.GameObject lianxing_right = UnityEngine.GameObject.Find("lianxing_right");
  70.         UnityEngine.GameObject faxing_left = UnityEngine.GameObject.Find("faxing_left");
  71.         UnityEngine.GameObject faxing_right = UnityEngine.GameObject.Find("faxing_right");
  72.         UnityEngine.GameObject wenshen_left = UnityEngine.GameObject.Find("wenshen_left");
  73.         UnityEngine.GameObject wenshen_right = UnityEngine.GameObject.Find("wenshen_right");
  74.        
  75.         UnityEngine.GameObject removeAvatarOkButton = UnityEngine.GameObject.Find("removeAvatarOkButton");
  76.         UnityEngine.GameObject removeAvatarCanelButton = UnityEngine.GameObject.Find("removeAvatarCanelButton");
  77.        
  78.         UIEventListener.Get(fuse_left).onClick = on_aspectItemClick;  
  79.         UIEventListener.Get(fuse_right).onClick = on_aspectItemClick;  
  80.         UIEventListener.Get(lianxing_left).onClick = on_aspectItemClick;  
  81.         UIEventListener.Get(lianxing_right).onClick = on_aspectItemClick;  
  82.         UIEventListener.Get(faxing_left).onClick = on_aspectItemClick;  
  83.         UIEventListener.Get(faxing_right).onClick = on_aspectItemClick;  
  84.         UIEventListener.Get(wenshen_left).onClick = on_aspectItemClick;  
  85.         UIEventListener.Get(wenshen_right).onClick = on_aspectItemClick;  
  86.        
  87.         UIEventListener.Get(avataritem1_focus_trigger).onClick = on_itemClick;  
  88.         UIEventListener.Get(avataritem1_focus_trigger).onHover = on_itemMouseOver;  
  89.        
  90.         UIEventListener.Get(avataritem2_focus_trigger).onClick = on_itemClick;  
  91.         UIEventListener.Get(avataritem2_focus_trigger).onHover = on_itemMouseOver;  
  92.        
  93.         UIEventListener.Get(avataritem3_focus_trigger).onClick = on_itemClick;  
  94.         UIEventListener.Get(avataritem3_focus_trigger).onHover = on_itemMouseOver;  
  95.        
  96.         UIEventListener.Get(avataritem4_focus_trigger).onClick = on_itemClick;  
  97.         UIEventListener.Get(avataritem4_focus_trigger).onHover = on_itemMouseOver;  
  98.        
  99.         UIEventListener.Get(avataritem5_focus_trigger).onClick = on_itemClick;  
  100.         UIEventListener.Get(avataritem5_focus_trigger).onHover = on_itemMouseOver;  
  101.        
  102.         UIEventListener.Get(avataritem6_focus_trigger).onClick = on_itemClick;  
  103.         UIEventListener.Get(avataritem6_focus_trigger).onHover = on_itemMouseOver;  
  104.        
  105.         UIEventListener.Get(skillitem1_focus_trigger).onClick = on_itemClick;  
  106.         UIEventListener.Get(skillitem1_focus_trigger).onHover = on_itemMouseOver;  
  107.        
  108.         UIEventListener.Get(skillitem2_focus_trigger).onClick = on_itemClick;  
  109.         UIEventListener.Get(skillitem2_focus_trigger).onHover = on_itemMouseOver;  
  110.        
  111.         UIEventListener.Get(skillitem3_focus_trigger).onClick = on_itemClick;  
  112.         UIEventListener.Get(skillitem3_focus_trigger).onHover = on_itemMouseOver;  
  113.        
  114.         UIEventListener.Get(createAvatarButton).onClick = on_createAvatarClick;  
  115.         UIEventListener.Get(removeAvatarButton).onClick = on_removeAvatarClick;  
  116.        
  117.         UIEventListener.Get(backbtn).onClick = on_backClick;  
  118.         UIEventListener.Get(entergame).onClick = on_entergameClick;  
  119.         UIEventListener.Get(goto_createavatarmode).onClick = on_gotocreateAvatarClick;  
  120.        
  121.         UIEventListener.Get(sel_list_item_focus1).onClick = on_selListItem1Click;  
  122.         UIEventListener.Get(sel_list_item_focus1).onHover = on_selListItemMouseOver;
  123.        
  124.         UIEventListener.Get(sel_list_item_focus2).onClick = on_selListItem2Click;  
  125.         UIEventListener.Get(sel_list_item_focus2).onHover = on_selListItemMouseOver;
  126.        
  127.         UIEventListener.Get(sel_list_item_focus3).onClick = on_selListItem3Click;  
  128.         UIEventListener.Get(sel_list_item_focus3).onHover = on_selListItemMouseOver;
  129.        
  130.         UIEventListener.Get(removeAvatarCanelButton).onClick = on_removeAvatarCanelClick;  
  131.         UIEventListener.Get(removeAvatarOkButton).onClick = on_removeAvatarOkClick;  
  132.     }
  133.    
  134.     // Use this for initialization
  135.     void Start () {
  136.         Common.DEBUG_MSG("selavatar_ui::Start: " + started);
  137.        
  138.         if(started == false)
  139.         {
  140.             started = true;
  141.             log_label.color = UnityEngine.Color.green;
  142.             log_label.text = "Getting List of Roles...";
  143.  
  144.             Monitor.Enter(KBEngineApp.app.entities);
  145.             Account account = (Account)KBEngineApp.app.player();
  146.             Monitor.Enter(account.avatars);
  147.             Dictionary<UInt64, Dictionary<string, object>> avatars = account.avatars;
  148.             Monitor.Exit(account.avatars);
  149.             Monitor.Exit(KBEngineApp.app.entities);
  150.  
  151.             onReqAvatarList(avatars);
  152.        
  153.             installEvents();
  154.         }
  155.        
  156.         windowsize = 30;
  157.         //autoSetPosition();
  158.     }
  159.    
  160.     void OnDestroy()
  161.     {
  162.         KBEngine.Event.deregisterOut(this);
  163.  
  164.         reset();
  165.         started = false;
  166.     }
  167.    
  168.     void installEvents()
  169.     {
  170.         KBEngine.Event.registerOut("onReqAvatarList", this, "onReqAvatarList");
  171.         KBEngine.Event.registerOut("onCreateAvatarResult", this, "onCreateAvatarResult");
  172.         KBEngine.Event.registerOut("onRemoveAvatar", this, "onRemoveAvatar");
  173.         KBEngine.Event.registerOut("onAvatarEnterWorld", this, "onAvatarEnterWorld");
  174.         KBEngine.Event.registerOut("onDisableConnect", this, "onDisableConnect");
  175.     }
  176.    
  177.     void hideModeUI()
  178.     {
  179.         List<UnityEngine.GameObject> createModeObjs = new List<UnityEngine.GameObject>();
  180.         List<UnityEngine.GameObject> selModeObjs = new List<UnityEngine.GameObject>();
  181.        
  182.         createModeObjs.Add(UnityEngine.GameObject.Find("item_selected"));
  183.        
  184.         createModeObjs.Add(UnityEngine.GameObject.Find("item1"));
  185.         createModeObjs.Add(UnityEngine.GameObject.Find("item2"));
  186.         createModeObjs.Add(UnityEngine.GameObject.Find("item3"));
  187.         createModeObjs.Add(UnityEngine.GameObject.Find("item4"));
  188.         createModeObjs.Add(UnityEngine.GameObject.Find("item5"));
  189.         createModeObjs.Add(UnityEngine.GameObject.Find("item6"));
  190.        
  191.         createModeObjs.Add(UnityEngine.GameObject.Find("item1_focus"));
  192.         createModeObjs.Add(UnityEngine.GameObject.Find("item2_focus"));
  193.         createModeObjs.Add(UnityEngine.GameObject.Find("item3_focus"));
  194.         createModeObjs.Add(UnityEngine.GameObject.Find("item4_focus"));
  195.         createModeObjs.Add(UnityEngine.GameObject.Find("item5_focus"));
  196.         createModeObjs.Add(UnityEngine.GameObject.Find("item6_focus"));
  197.        
  198.         createModeObjs.Add(UnityEngine.GameObject.Find("skill_item1"));
  199.         createModeObjs.Add(UnityEngine.GameObject.Find("skill_item2"));
  200.         createModeObjs.Add(UnityEngine.GameObject.Find("skill_item3"));
  201.        
  202.         createModeObjs.Add(UnityEngine.GameObject.Find("skill_item1_focus"));
  203.         createModeObjs.Add(UnityEngine.GameObject.Find("skill_item2_focus"));
  204.         createModeObjs.Add(UnityEngine.GameObject.Find("skill_item3_focus"));
  205.        
  206.         createModeObjs.Add(UnityEngine.GameObject.Find("avatarlist_label"));
  207.         createModeObjs.Add(UnityEngine.GameObject.Find("skilllist_label"));
  208.        
  209.         createModeObjs.Add(UnityEngine.GameObject.Find("create_username"));
  210.         createModeObjs.Add(UnityEngine.GameObject.Find("createAvatarButton"));
  211.        
  212.         createModeObjs.Add(UnityEngine.GameObject.Find("removeAvatarInputName"));
  213.         selModeObjs.Add(UnityEngine.GameObject.Find("removeAvatarInputName"));
  214.        
  215.         selModeObjs.Add(UnityEngine.GameObject.Find("entergame"));
  216.         selModeObjs.Add(UnityEngine.GameObject.Find("goto_createavatarmode"));
  217.         selModeObjs.Add(UnityEngine.GameObject.Find("removeAvatarButton"));
  218.        
  219.         if(isCreateMode == true)
  220.             selModeObjs.Add(UnityEngine.GameObject.Find("sel_list_item_panel1"));
  221.         else
  222.             if(showAvatars[0] == false)
  223.                 createModeObjs.Add(UnityEngine.GameObject.Find("sel_list_item_panel1"));
  224.        
  225.         if(isCreateMode == true)
  226.             selModeObjs.Add(UnityEngine.GameObject.Find("sel_list_item_panel2"));
  227.         else
  228.             if(showAvatars[1] == false)
  229.                 createModeObjs.Add(UnityEngine.GameObject.Find("sel_list_item_panel2"));
  230.        
  231.         if(isCreateMode == true)
  232.             selModeObjs.Add(UnityEngine.GameObject.Find("sel_list_item_panel3"));
  233.         else
  234.             if(showAvatars[2] == false)
  235.                 createModeObjs.Add(UnityEngine.GameObject.Find("sel_list_item_panel3"));
  236.        
  237.         selModeObjs.Add(UnityEngine.GameObject.Find("sel_list_item_focus"));
  238.         selModeObjs.Add(UnityEngine.GameObject.Find("sel_list_item_selected_focus"));
  239.            
  240.         if(isCreateMode)
  241.         {
  242.             for(int i=0; i<selModeObjs.Count; i++)
  243.             {
  244.                 Vector3 pos = selModeObjs[i].transform.localPosition;
  245.                 pos.y = 99999.0f;
  246.                 selModeObjs[i].transform.localPosition = pos;
  247.             }
  248.            
  249.             hideSelListItemFocus();
  250.             selectItemFocus(UnityEngine.GameObject.Find(currsel_item));
  251.         }
  252.         else{
  253.             for(int i=0; i<createModeObjs.Count; i++)
  254.             {
  255.                 Vector3 pos = createModeObjs[i].transform.localPosition;
  256.                 pos.y = 99999.0f;
  257.                 createModeObjs[i].transform.localPosition = pos;
  258.             }
  259.            
  260.             hideItemFocus();
  261.            
  262.             on_selListItem1Click(UnityEngine.GameObject.Find(currsel_selListItem));
  263.         }
  264.     }
  265.    
  266.     void autoSetPosition()
  267.     {
  268.         if(windowsize == Screen.width + Screen.height)
  269.             return;
  270.        
  271.         UnityEngine.GameObject go = UnityEngine.GameObject.Find("avatars_panel");
  272.        
  273.         windowsize = Screen.width + Screen.height;
  274.        
  275.         Vector3 pos = go.transform.localPosition;
  276.        
  277.         float x = (-((float)(Screen.width / 2))) + ((float)go.GetComponent<UITexture>().width / 2) + 0.5f;
  278.         float y = 0.0f;
  279.         pos.x = x;
  280.         pos.y = y;
  281.         go.transform.localPosition = pos;
  282.         Common.DEBUG_MSG("screen-size: x=" + Screen.width + "y=" + Screen.height);
  283.         Common.DEBUG_MSG("avatar-panel-tu: x=" + go.GetComponent<UITexture>().width + "y=" + go.GetComponent<UITexture>().height);
  284.         Common.DEBUG_MSG("avatar-panel: x=" + x + "y=" + y);
  285.        
  286.         UnityEngine.GameObject fuse_left = UnityEngine.GameObject.Find("fuse_left");
  287.         UnityEngine.GameObject fuse_right = UnityEngine.GameObject.Find("fuse_right");
  288.         UnityEngine.GameObject lianxing_left = UnityEngine.GameObject.Find("lianxing_left");
  289.         UnityEngine.GameObject lianxing_right = UnityEngine.GameObject.Find("lianxing_right");
  290.         UnityEngine.GameObject faxing_left = UnityEngine.GameObject.Find("faxing_left");
  291.         UnityEngine.GameObject faxing_right = UnityEngine.GameObject.Find("faxing_right");
  292.         UnityEngine.GameObject wenshen_left = UnityEngine.GameObject.Find("wenshen_left");
  293.         UnityEngine.GameObject wenshen_right = UnityEngine.GameObject.Find("wenshen_right");
  294.        
  295.         UnityEngine.GameObject avataritem1 = UnityEngine.GameObject.Find("item1");
  296.         UnityEngine.GameObject avataritem2 = UnityEngine.GameObject.Find("item2");
  297.         UnityEngine.GameObject avataritem3 = UnityEngine.GameObject.Find("item3");
  298.         UnityEngine.GameObject avataritem4 = UnityEngine.GameObject.Find("item4");
  299.         UnityEngine.GameObject avataritem5 = UnityEngine.GameObject.Find("item5");
  300.         UnityEngine.GameObject avataritem6 = UnityEngine.GameObject.Find("item6");
  301.        
  302.         UnityEngine.GameObject avataritem1_focus_trigger = UnityEngine.GameObject.Find("item1_focus");
  303.         UnityEngine.GameObject avataritem2_focus_trigger = UnityEngine.GameObject.Find("item2_focus");
  304.         UnityEngine.GameObject avataritem3_focus_trigger = UnityEngine.GameObject.Find("item3_focus");
  305.         UnityEngine.GameObject avataritem4_focus_trigger = UnityEngine.GameObject.Find("item4_focus");
  306.         UnityEngine.GameObject avataritem5_focus_trigger = UnityEngine.GameObject.Find("item5_focus");
  307.         UnityEngine.GameObject avataritem6_focus_trigger = UnityEngine.GameObject.Find("item6_focus");
  308.        
  309.         UnityEngine.GameObject skillitem1 = UnityEngine.GameObject.Find("skill_item1");
  310.         UnityEngine.GameObject skillitem2 = UnityEngine.GameObject.Find("skill_item2");
  311.         UnityEngine.GameObject skillitem3 = UnityEngine.GameObject.Find("skill_item3");
  312.        
  313.         UnityEngine.GameObject skillitem1_focus_trigger = UnityEngine.GameObject.Find("skill_item1_focus");
  314.         UnityEngine.GameObject skillitem2_focus_trigger = UnityEngine.GameObject.Find("skill_item2_focus");
  315.         UnityEngine.GameObject skillitem3_focus_trigger = UnityEngine.GameObject.Find("skill_item3_focus");
  316.        
  317.         UnityEngine.GameObject avatarlist_label = UnityEngine.GameObject.Find("avatarlist_label");
  318.         UnityEngine.GameObject skilllist_label = UnityEngine.GameObject.Find("skilllist_label");
  319.        
  320.         UnityEngine.GameObject create_username = UnityEngine.GameObject.Find("create_username");
  321.         UnityEngine.GameObject createAvatarButton = UnityEngine.GameObject.Find("createAvatarButton");
  322.         UnityEngine.GameObject removeAvatarButton = UnityEngine.GameObject.Find("removeAvatarButton");
  323.         UnityEngine.GameObject removeAvatarInputName = UnityEngine.GameObject.Find("removeAvatarInputName");
  324.         UnityEngine.GameObject backbtn = UnityEngine.GameObject.Find("back");
  325.         UnityEngine.GameObject entergame = UnityEngine.GameObject.Find("entergame");
  326.         UnityEngine.GameObject goto_createavatarmode = UnityEngine.GameObject.Find("goto_createavatarmode");
  327.        
  328.         UnityEngine.GameObject sel_list_item_panel1 = UnityEngine.GameObject.Find("sel_list_item_panel1");
  329.         UnityEngine.GameObject sel_list_item_panel2 = UnityEngine.GameObject.Find("sel_list_item_panel2");
  330.         UnityEngine.GameObject sel_list_item_panel3 = UnityEngine.GameObject.Find("sel_list_item_panel3");
  331.        
  332.         UnityEngine.GameObject human_descr = UnityEngine.GameObject.Find("human_descr");
  333.         UnityEngine.GameObject skills_descr = UnityEngine.GameObject.Find("skills_descr");
  334.        
  335.         hideItemFocus();
  336.         hideSelListItemFocus();
  337.  
  338.         int width = avataritem1.GetComponent<UITexture>().mainTexture.width;
  339.         int height = avataritem1.GetComponent<UITexture>().mainTexture.height;
  340.        
  341.         pos.x = x;
  342.         pos.y = y;
  343.         pos.z = -1.0f;
  344.         pos.x -= 0.0f;
  345.         pos.y += (((float)go.GetComponent<UITexture>().height / 2) - height) + 10.0f;
  346.         avatarlist_label.transform.localPosition = pos;
  347.        
  348.         pos.x = x;
  349.         pos.y = y;
  350.         pos.z = -1.0f;
  351.        
  352.         pos.x -= 0.0f;
  353.         pos.y -= 15.0f;
  354.         skilllist_label.transform.localPosition = pos;
  355.        
  356.         pos.x = x;
  357.         pos.y = y;
  358.         pos.z = -1.0f;
  359.        
  360.         pos.x -= 35.0f;
  361.         pos.y += (((float)go.GetComponent<UITexture>().height / 2) - height) - 35.0f;
  362.         avataritem1.transform.localPosition = pos;
  363.  
  364.         pos.z = -2.0f;
  365.         avataritem1_focus_trigger.transform.localPosition = pos;
  366.         pos = avataritem1.transform.localPosition;
  367.         pos.y -= height;
  368.         pos.z = -1.0f;
  369.         avataritem2.transform.localPosition = pos;
  370.  
  371.         pos.z = -2.0f;
  372.         avataritem2_focus_trigger.transform.localPosition = pos;
  373.  
  374.         pos = avataritem2.transform.localPosition;
  375.         pos.y -= height;
  376.         pos.z = -1.0f;
  377.         avataritem3.transform.localPosition = pos;
  378.  
  379.         pos.z = -2.0f;
  380.         avataritem3_focus_trigger.transform.localPosition = pos;
  381.  
  382.         pos.x = x;
  383.         pos.y = y;
  384.         pos.z = -1.0f;
  385.  
  386.         pos.x += 35.0f;
  387.         pos.y += (((float)go.GetComponent<UITexture>().height / 2) - height) - 35.0f;
  388.         avataritem4.transform.localPosition = pos;
  389.  
  390.         pos.z = -2.0f;
  391.         avataritem4_focus_trigger.transform.localPosition = pos;
  392.  
  393.         pos = avataritem4.transform.localPosition;
  394.         pos.y -= height;
  395.         pos.z = -1.0f;
  396.         avataritem5.transform.localPosition = pos;
  397.  
  398.         pos.z = -2.0f;
  399.         avataritem5_focus_trigger.transform.localPosition = pos;
  400.  
  401.         pos = avataritem5.transform.localPosition;
  402.         pos.y -= height;
  403.         pos.z = -1.0f;
  404.         avataritem6.transform.localPosition = pos;
  405.  
  406.         pos.z = -2.0f;
  407.         avataritem6_focus_trigger.transform.localPosition = pos;
  408.  
  409.         //-----------------------------------------------------------
  410.         pos.x = x;
  411.         pos.y = y;
  412.         pos.z = -1.0f;
  413.        
  414.         pos.x -= 60.0f;
  415.         pos.y -= 55.0f;
  416.         skillitem1.transform.localPosition = pos;
  417.        
  418.         pos.z = -2.0f;
  419.         skillitem1_focus_trigger.transform.localPosition = pos;
  420.        
  421.         pos = skillitem1.transform.localPosition;
  422.         pos.x += 60;
  423.         pos.z = -1.0f;
  424.         skillitem2.transform.localPosition = pos;
  425.        
  426.         pos.z = -2.0f;
  427.         skillitem2_focus_trigger.transform.localPosition = pos;
  428.        
  429.         pos = skillitem2.transform.localPosition;
  430.         pos.x += 60;
  431.         pos.z = -1.0f;
  432.         skillitem3.transform.localPosition = pos;
  433.        
  434.         pos.z = -2.0f;
  435.         skillitem3_focus_trigger.transform.localPosition = pos;
  436.        
  437.         //-----------------------------------------------------------
  438.         selectItemFocus(UnityEngine.GameObject.Find(currsel_item));
  439.         selectSelListItemFocus(UnityEngine.GameObject.Find(currsel_selListItem));
  440.        
  441.         //-----------------------------------------------------------
  442.         pos = create_username.transform.localPosition;
  443.         pos.y = -(Screen.height / 2 - 50.0f);
  444.         create_username.transform.localPosition = pos;
  445.        
  446.         pos = createAvatarButton.transform.localPosition;
  447.         pos.y = -(Screen.height / 2 - 15.0f);
  448.         createAvatarButton.transform.localPosition = pos;
  449.            
  450.         pos = entergame.transform.localPosition;
  451.         pos.y = -(Screen.height / 2 - 15.0f);
  452.         entergame.transform.localPosition = pos;
  453.        
  454.         pos = removeAvatarInputName.transform.localPosition;
  455.         pos.x = -((Screen.width / 2) * 0.15f);
  456.         pos.y = 0.0f;
  457.         removeAvatarInputName.transform.localPosition = pos;
  458.            
  459.         pos = backbtn.transform.localPosition;
  460.         pos.x = (Screen.width / 2 - 100.0f);
  461.         pos.y = -(Screen.height / 2 - 15.0f);
  462.         backbtn.transform.localPosition = pos;
  463.        
  464.         pos = removeAvatarButton.transform.localPosition;
  465.         pos.x = (Screen.width / 2 - 100.0f);
  466.         pos.y = -(Screen.height / 2 - 45.0f);
  467.         removeAvatarButton.transform.localPosition = pos;
  468.        
  469.         pos = goto_createavatarmode.transform.localPosition;
  470.         pos.x = (Screen.width / 2 - 100.0f);
  471.         pos.y = -(Screen.height / 2 - 75.0f);
  472.         goto_createavatarmode.transform.localPosition = pos;
  473.        
  474.         //-----------------------------------------------------------
  475.         pos.x = x;
  476.         pos.y = y;
  477.         pos.z = -1.0f;
  478.        
  479.         pos.x -= 60.0f;
  480.         pos.y += (((float)go.GetComponent<UITexture>().height / 2) - height) - 10.0f;
  481.         sel_list_item_panel1.transform.localPosition = pos;
  482.        
  483.         pos.x = x;
  484.         pos.y = y;
  485.         pos.z = -1.0f;
  486.        
  487.         pos.x -= 60.0f;
  488.         pos.y += (((float)go.GetComponent<UITexture>().height / 2) - height) - 80.0f;
  489.         sel_list_item_panel2.transform.localPosition = pos;
  490.        
  491.         pos.x = x;
  492.         pos.y = y;
  493.         pos.z = -1.0f;
  494.        
  495.         pos.x -= 60.0f;
  496.         pos.y += (((float)go.GetComponent<UITexture>().height / 2) - height) - 150.0f;
  497.         sel_list_item_panel3.transform.localPosition = pos;
  498.  
  499.         //-------------------------------------------------------------
  500.         pos.x = x;
  501.         pos.y = y;
  502.         pos.z = -1.0f;
  503.         pos.x += 20.0f;
  504.         pos.y += (((float)go.GetComponent<UITexture>().height / 2) - height) - 300.0f;
  505.         fuse_left.transform.localPosition = pos;
  506.         pos.x += 30.0f;
  507.         fuse_right.transform.localPosition = pos;
  508.        
  509.         pos.x = x;
  510.         pos.y = y;
  511.         pos.z = -1.0f;
  512.         pos.x += 20.0f;
  513.         pos.y += (((float)go.GetComponent<UITexture>().height / 2) - height) - 328.0f;
  514.         lianxing_left.transform.localPosition = pos;
  515.         pos.x += 30.0f;
  516.         lianxing_right.transform.localPosition = pos;
  517.        
  518.         pos.x = x;
  519.         pos.y = y;
  520.         pos.z = -1.0f;
  521.         pos.x += 20.0f;
  522.         pos.y += (((float)go.GetComponent<UITexture>().height / 2) - height) - 355.0f;
  523.         faxing_left.transform.localPosition = pos;
  524.         pos.x += 30.0f;
  525.         faxing_right.transform.localPosition = pos;
  526.        
  527.         pos.x = x;
  528.         pos.y = y;
  529.         pos.z = -1.0f;
  530.         pos.x += 20.0f;
  531.         pos.y += (((float)go.GetComponent<UITexture>().height / 2) - height) - 382.0f;
  532.         wenshen_left.transform.localPosition = pos;
  533.         pos.x += 30.0f;
  534.         wenshen_right.transform.localPosition = pos;
  535.        
  536.         hideModeUI();
  537.  
  538.         //-----------------------------------------------------------
  539.         pos = human_descr.transform.localPosition;
  540.        
  541.         x = ((float)(Screen.width / 2)) - human_descr.GetComponentInChildren<UITexture>().width / 2 - 0.5f;
  542.         y = 0.0f;
  543.         pos.x = x;
  544.         pos.y = ((float)(Screen.height / 2)) - (skills_descr.GetComponentInChildren<UITexture>().height / 2) - 0.5f;
  545.         human_descr.transform.localPosition = pos;
  546.        
  547.         pos = skills_descr.transform.localPosition;
  548.        
  549.         x = ((float)(Screen.width / 2)) - skills_descr.GetComponentInChildren<UITexture>().width / 2 - 0.5f;
  550.         y = 0.0f;
  551.         pos.x = x;
  552.         pos.y = -100.0f;
  553.         skills_descr.transform.localPosition = pos;
  554.     }
  555.    
  556.     // Update is called once per frame
  557.     void Update () {
  558.         autoSetPosition();
  559.     }
  560.    
  561.     void FixedUpdate()
  562.     {
  563.         updateLoadAvatarInfo();
  564.     }
  565.    
  566.     void updateLoadAvatarInfo()
  567.     {
  568.         if(loadAvatar_label == null || loader.inst == null)
  569.             return;
  570.        
  571.         if(loadAvatar_label.text != "")
  572.         {
  573.             Scene selavatarScene = loader.inst.findScene("selavatar", false);
  574.             if(selavatarScene == null)
  575.                 return;
  576.  
  577.             foreach(KeyValuePair<string, SceneObject> obj in selavatarScene.objs)
  578.             {
  579.                 SceneObject sobj = obj.Value;
  580.                 if(sobj.asset == null)
  581.                     continue;
  582.  
  583.                 Byte rtype = Srouce2roleType(sobj.asset.source);
  584.                
  585.                 if(rtype > 0)
  586.                 {
  587.                     if(rtype == changeAvatarItem)
  588.                     {
  589.                         if(sobj.asset != null && sobj.asset.isLoaded == false)
  590.                         {
  591.                             if(sobj.asset.load != null && sobj.asset.load.www != null)
  592.                             {
  593.                                 if(sobj.asset.load.www.error != null)
  594.                                     loadAvatar_label.text = "加载角色模型失败, 重试中...";
  595.                                 else
  596.                                     loadAvatar_label.text = "正在加载角色模型(" + ((int)(sobj.asset.load.www.progress * 100))+ "%)...";
  597.                             }
  598.                         }
  599.                         else
  600.                         {
  601.                             loadAvatar_label.text = "";
  602.                         }
  603.                     }
  604.                 }
  605.             }
  606.         }
  607.     }
  608.    
  609.     void refreshAvatarListIcon()
  610.     {
  611.         if(avatarList.Count > 0)
  612.         {
  613.             AvatarInfo ainfo = avatarList[0];
  614.             UnityEngine.GameObject.Find("sel_list_item1").GetComponent<UITexture>().mainTexture =
  615.                 UnityEngine.GameObject.Find("item" + ainfo.roleType).GetComponent<UITexture>().mainTexture;
  616.         }
  617.        
  618.         if(avatarList.Count > 1)
  619.         {
  620.             AvatarInfo ainfo = avatarList[1];
  621.             UnityEngine.GameObject.Find("sel_list_item2").GetComponent<UITexture>().mainTexture =
  622.                 UnityEngine.GameObject.Find("item" + ainfo.roleType).GetComponent<UITexture>().mainTexture;
  623.         }
  624.        
  625.         if(avatarList.Count > 2)
  626.         {
  627.             AvatarInfo ainfo = avatarList[2];
  628.             UnityEngine.GameObject.Find("sel_list_item3").GetComponent<UITexture>().mainTexture =
  629.                 UnityEngine.GameObject.Find("item" + ainfo.roleType).GetComponent<UITexture>().mainTexture;
  630.         }
  631.     }
  632.    
  633.     void hideItemFocus()
  634.     {
  635.         UnityEngine.GameObject avataritem_focus = UnityEngine.GameObject.Find("item_focus");
  636.         Vector3 pos = avataritem_focus.transform.position;
  637.         pos.y = -99999.0f;
  638.         avataritem_focus.transform.position = pos;
  639.     }
  640.    
  641.     void showItemFocus(UnityEngine.GameObject item)
  642.     {
  643.         UnityEngine.GameObject item_focus = UnityEngine.GameObject.Find("item_focus");
  644.         Vector3 pos = item.transform.localPosition;
  645.         pos.z = -100.0f;
  646.         item_focus.transform.localPosition = pos;
  647.     }
  648.    
  649.     void hideSelListItemFocus()
  650.     {
  651.         UnityEngine.GameObject avataritem_focus = UnityEngine.GameObject.Find("sel_list_item_focus");
  652.         Vector3 pos = avataritem_focus.transform.position;
  653.         pos.y = -99999.0f;
  654.         avataritem_focus.transform.position = pos;
  655.     }
  656.    
  657.     void showSelListItemFocus(UnityEngine.GameObject item)
  658.     {
  659.         UnityEngine.GameObject item_focus = UnityEngine.GameObject.Find("sel_list_item_focus");
  660.         Vector3 pos = item.transform.parent.localPosition;
  661.         pos.x += 60.0f;
  662.         pos.z = -100.0f;
  663.         item_focus.transform.localPosition = pos;
  664.     }
  665.    
  666.     void selectItemFocus(UnityEngine.GameObject item)
  667.     {
  668.         UnityEngine.GameObject item_selected_focus = UnityEngine.GameObject.Find("item_selected");
  669.         Vector3 pos = item.transform.localPosition;
  670.         pos.z = -101.0f;
  671.         item_selected_focus.transform.localPosition = pos;
  672.     }
  673.    
  674.     void selectSelListItemFocus(UnityEngine.GameObject item)
  675.     {
  676.         UnityEngine.GameObject item_focus = UnityEngine.GameObject.Find("sel_list_item_selected_focus");
  677.         Vector3 pos = item.transform.parent.localPosition;
  678.         pos.x += 60.0f;
  679.         pos.z = -101.0f;
  680.         item_focus.transform.localPosition = pos;
  681.     }
  682.    
  683.     void on_aspectItemClick(UnityEngine.GameObject item)
  684.     {
  685.         Common.DEBUG_MSG("on_aspectItemClick: " + item.name);
  686.        
  687.         SceneObject obj = getCurrentAvatarObject();
  688.         if(obj == null)
  689.             return;
  690.        
  691.         curravatar avatar = obj.gameObject.GetComponent<curravatar>();
  692.  
  693.         if(item.name == "fuse_left")
  694.         {
  695.             avatar.decFuse();
  696.         }
  697.         else if(item.name == "fuse_right")
  698.         {
  699.             avatar.incFuse();
  700.         }
  701.         else if(item.name == "lianxing_left")
  702.         {
  703.            
  704.         }
  705.         else if(item.name == "lianxing_right")
  706.         {
  707.            
  708.         }
  709.         else if(item.name == "faxing_left")
  710.         {
  711.            
  712.         }
  713.         else if(item.name == "faxing_right")
  714.         {
  715.            
  716.         }
  717.         else if(item.name == "wenshen_left")
  718.         {
  719.            
  720.         }
  721.         else if(item.name == "wenshen_right")
  722.         {
  723.            
  724.         }
  725.     }
  726.    
  727.     void on_itemMouseOver(UnityEngine.GameObject item, bool isOver)
  728.     {
  729.         Common.DEBUG_MSG("on_itemMouseOver: " + item.name + " " + isOver);
  730.         if(isOver == true)
  731.             showItemFocus(item);
  732.         else
  733.             hideItemFocus();
  734.     }
  735.    
  736.     void on_itemClick(UnityEngine.GameObject item)
  737.     {
  738.         Common.DEBUG_MSG("on_itemClick: " + item.name);
  739.        
  740.         UnityEngine.GameObject human_descr = UnityEngine.GameObject.Find("human_descr");
  741.         UnityEngine.GameObject skills_descr = UnityEngine.GameObject.Find("skills_descr");
  742.        
  743.         if(item.name.IndexOf("skill") <= -1)
  744.         {
  745.             currsel_item = item.name;
  746.            
  747.             selectItemFocus(item);
  748.            
  749.             if(currsel_item == "item1_focus")
  750.             {
  751.                 changeAvatarItem = 1;
  752.                 human_descr.GetComponentInChildren<UILabel>().text = "战士是真正的武器大师,攻击狂野而致命,每一击都体现了千锤百炼的高超剑技。 在战场上,战士们永远都在最前线,坚固的护甲以及不屈的意志,保护同伴,勇往直前,用血肉之躯杀出通往胜利的血路。";
  753.                 skills_descr.GetComponentInChildren<UILabel>().text = "必杀技: 毁灭\r\n" +
  754.                     "使出全身的力量对敌人造成毁灭性的打击。";
  755.             }
  756.             else if(currsel_item == "item2_focus")
  757.             {
  758.                 changeAvatarItem = 2;
  759.                 human_descr.GetComponentInChildren<UILabel>().text = "法师是神秘与危险的化身,天地魔力的掌控者。法师使用魔法时天地色变、大地为之颤抖,大范围的魔法技能威力无与伦比。";
  760.                         skills_descr.GetComponentInChildren<UILabel>().text = "必杀技: 死神降临\r\n" +
  761.                     "使出全身的力量对敌人造成毁灭性的打击。";
  762.             }
  763.             else if(currsel_item == "item3_focus")
  764.             {
  765.                 changeAvatarItem = 3;
  766.                 human_descr.GetComponentInChildren<UILabel>().text = "1法师是神秘与危险的化身,天地魔力的掌控者。法师使用魔法时天地色变、大地为之颤抖,大范围的魔法技能威力无与伦比。";
  767.             }
  768.             else if(currsel_item == "item4_focus")
  769.             {
  770.                 changeAvatarItem = 4;
  771.                 human_descr.GetComponentInChildren<UILabel>().text = "2法师是神秘与危险的化身,天地魔力的掌控者。法师使用魔法时天地色变、大地为之颤抖,大范围的魔法技能威力无与伦比。";
  772.             }
  773.             else if(currsel_item == "item5_focus")
  774.             {
  775.                 changeAvatarItem = 5;
  776.                 human_descr.GetComponentInChildren<UILabel>().text = "3法师是神秘与危险的化身,天地魔力的掌控者。法师使用魔法时天地色变、大地为之颤抖,大范围的魔法技能威力无与伦比。";
  777.             }
  778.             else if(currsel_item == "item6_focus")
  779.             {
  780.                 changeAvatarItem = 6;
  781.                 human_descr.GetComponentInChildren<UILabel>().text = "未开放这个职业。";
  782.             }
  783.            
  784.             resetSelAvatar();
  785.         }
  786.     }
  787.    
  788.     void on_createAvatarClick(UnityEngine.GameObject obj)
  789.     {
  790.         Common.DEBUG_MSG("on_createAvatarClick: " + obj.name);
  791.        
  792.         UnityEngine.GameObject create_usernameLabel = UnityEngine.GameObject.Find("create_usernameLabel");
  793.        
  794.  
  795.         string name = create_usernameLabel.GetComponent<UILabel>().text;
  796.         if(name.Length < 2)
  797.         {
  798.             log_label.color = UnityEngine.Color.red;
  799.             log_label.text = "角色名称必须大于2位!";
  800.             return;
  801.         }
  802.        
  803.         log_label.color = UnityEngine.Color.green;
  804.         log_label.text = "请求中请稍后...";
  805.        
  806.         Monitor.Enter(KBEngineApp.app.entities);
  807.         Account account = (Account)KBEngineApp.app.player();
  808.         account.reqCreateAvatar(changeAvatarItem, name);
  809.         Monitor.Exit(KBEngineApp.app.entities);
  810.     }
  811.    
  812.     void on_removeAvatarClick(UnityEngine.GameObject obj)
  813.     {      
  814.         Common.DEBUG_MSG("on_removeAvatarClick: " + obj.name);
  815.        
  816.         UnityEngine.GameObject removeAvatarInput = UnityEngine.GameObject.Find("removeAvatarInputName");
  817.         Vector3 pos = removeAvatarInput.transform.localPosition;
  818.         pos.y = 0.0f;
  819.         removeAvatarInput.transform.localPosition = pos;
  820.     }
  821.    
  822.     void on_backClick(UnityEngine.GameObject obj)
  823.     {
  824.         if(obj != null)
  825.             Common.DEBUG_MSG("on_backClick: " + obj.name);
  826.        
  827.         log_label.color = UnityEngine.Color.green;
  828.         log_label.text = "";
  829.         windowsize = 90;
  830.        
  831.         if(isCreateMode == true)
  832.         {
  833.             isCreateMode = false;
  834.             refreshAvatarListIcon();
  835.             return;
  836.         }
  837.        
  838.         // back to login
  839.         loader.inst.enterScene("login");
  840.     }
  841.    
  842.     void on_gotocreateAvatarClick(UnityEngine.GameObject obj)
  843.     {
  844.         if(obj != null)
  845.             Common.DEBUG_MSG("on_gotocreateAvatarClick: " + obj.name);
  846.        
  847.         isCreateMode = true;
  848.         windowsize = 0;
  849.         changeAvatarItem = 1;
  850.         resetSelAvatar();
  851.        
  852.         List < string > loads = new List < string >();
  853.         loads.Add("avatar1.unity3d");
  854.         loads.Add("avatar2.unity3d");
  855.         loads.Add("avatar3.unity3d");
  856.         loads.Add("avatar4.unity3d");
  857.         loads.Add("avatar_wpgroup.unity3d");
  858.        
  859.         for(int i=0; i<loads.Count; i++)
  860.         {
  861.             string loadRes = loads[i];
  862.             Asset asset = null;
  863.            
  864.             foreach(KeyValuePair<string, Asset> assetsCache in Scene.assetsCache)
  865.             {
  866.                 if(assetsCache.Value.source == loadRes)
  867.                 {
  868.                     asset = assetsCache.Value;
  869.                     break;
  870.                 }
  871.             }
  872.            
  873.             if(asset == null)
  874.             {
  875.                 Common.ERROR_MSG("on_gotocreateAvatarClick: not found asset " + loadRes);
  876.                 continue;
  877.             }
  878.            
  879.             asset.loadLevel = Asset.LOAD_LEVEL.LEVEL_ENTER_AFTER;
  880.             if(i == 0)
  881.                 asset.loadPri = 1;
  882.                
  883.             loader.inst.loadPool.addLoad(asset);
  884.         }
  885.        
  886.         if(loads.Count > 0)
  887.             loader.inst.loadPool.start();
  888.     }
  889.    
  890.     void on_entergameClick(UnityEngine.GameObject obj)
  891.     {
  892.         Common.DEBUG_MSG("on_entergameClick: " + obj.name);
  893.  
  894.         int idx = -1;
  895.         if(currsel_selListItem == "sel_list_item_focus1")
  896.         {
  897.             idx = 0;
  898.         }
  899.         else if(currsel_selListItem == "sel_list_item_focus2")
  900.         {
  901.             idx = 1;
  902.         }
  903.         else if(currsel_selListItem == "sel_list_item_focus3")
  904.         {
  905.             idx = 2;
  906.         }
  907.        
  908.         if(idx == -1)
  909.         {
  910.             log_label.color = UnityEngine.Color.red;
  911.             log_label.text = "请选择一个角色。";
  912.             return;
  913.         }
  914.        
  915.         AvatarInfo info = avatarList[idx];
  916.        
  917.         log_label.color = UnityEngine.Color.green;
  918.         log_label.text = "请求中请稍后...";
  919.        
  920.         Monitor.Enter(KBEngineApp.app.entities);
  921.         Account account = (Account)KBEngineApp.app.player();
  922.         account.selectAvatarGame(info.dbid);
  923.         Monitor.Exit(KBEngineApp.app.entities);
  924.        
  925.     }
  926.  
  927.     void on_selListItemMouseOver(UnityEngine.GameObject item, bool isOver)
  928.     {
  929.         if(isOver == true)
  930.             showSelListItemFocus(item);
  931.         else
  932.             hideSelListItemFocus();
  933.     }
  934.    
  935.     void resetSelAvatar()
  936.     {
  937.         bool loadAvatar = false;
  938.        
  939.         if(loadAvatar_label != null)
  940.             loadAvatar_label.text = "";
  941.        
  942.         foreach(KeyValuePair<string, SceneObject> obj in loader.inst.findScene("selavatar", false).objs)
  943.         {
  944.             SceneObject sobj = obj.Value;
  945.             Byte rtype = Srouce2roleType(sobj.asset.source);
  946.            
  947.             if(rtype > 0)
  948.             {
  949.                 Common.DEBUG_MSG("resetSelAvatar: rtype=" + rtype + ", source=" + sobj.asset.source);
  950.                 curravatar avatar = null;
  951.                 if(sobj.gameObject != null)
  952.                 {
  953.                     avatar = sobj.gameObject.GetComponent<curravatar>();
  954.                 }
  955.                
  956.                 if(rtype == changeAvatarItem)
  957.                 {
  958.                     sobj.position = sobj.position;
  959.                     sobj.eulerAngles = sobj.eulerAngles;
  960.                     sobj.scale = sobj.scale;
  961.                    
  962.                     if(avatar != null)
  963.                     {
  964.                         loadAvatar = (sobj.asset.isLoaded == false);
  965.                         NGUITools.SetActive(avatar.transform.gameObject, true);
  966.                     }
  967.                     else
  968.                         loadAvatar = true;
  969.                 }
  970.                 else
  971.                 {
  972.                     if(avatar != null)
  973.                         NGUITools.SetActive(avatar.transform.gameObject, false);
  974.                 }
  975.             }
  976.         }
  977.        
  978.         if(loadAvatar == true)
  979.         {
  980.             if(loadAvatar_label != null)
  981.                 loadAvatar_label.text = "正在加载角色模型(0%)...";
  982.         }
  983.     }
  984.    
  985.     SceneObject getCurrentAvatarObject()
  986.     {
  987.         foreach(KeyValuePair<string, SceneObject> obj in loader.inst.findScene("selavatar", false).objs)
  988.         {
  989.             SceneObject sobj = obj.Value;
  990.             Byte rtype = Srouce2roleType(sobj.asset.source);
  991.             if(rtype > 0 && rtype == changeAvatarItem)
  992.             {
  993.                 return sobj;
  994.             }
  995.         }
  996.        
  997.         return null;
  998.     }
  999.    
  1000.     void on_selListItem1Click(UnityEngine.GameObject item)
  1001.     {
  1002.         if(item == null)
  1003.             return;
  1004.        
  1005.         currsel_selListItem = item.name;
  1006.         changeAvatarItem = 0;
  1007.  
  1008.         if(avatarList.Count > 0)
  1009.         {
  1010.             AvatarInfo info = avatarList[0];
  1011.             changeAvatarItem = info.roleType;
  1012.         }
  1013.    
  1014.         selectSelListItemFocus(item);
  1015.        
  1016.         UnityEngine.GameObject human_descr = UnityEngine.GameObject.Find("human_descr");
  1017.         UnityEngine.GameObject skills_descr = UnityEngine.GameObject.Find("skills_descr");
  1018.         human_descr.GetComponentInChildren<UILabel>().text = "角色目前还很脆弱哦, 您当前可以找XXX去做任务获得经验。";
  1019.         skills_descr.GetComponentInChildren<UILabel>().text = "您可以去兽人洞穴击杀boss获得xx技能书来提升打击能力。";
  1020.        
  1021.         resetSelAvatar();
  1022.     }
  1023.    
  1024.     void on_selListItem2Click(UnityEngine.GameObject item)
  1025.     {
  1026.         currsel_selListItem = item.name;
  1027.         changeAvatarItem = 0;
  1028.        
  1029.         if(avatarList.Count > 0)
  1030.         {
  1031.             AvatarInfo info = avatarList[1];
  1032.             changeAvatarItem = info.roleType;
  1033.         }
  1034.        
  1035.         selectSelListItemFocus(item);
  1036.        
  1037.         UnityEngine.GameObject human_descr = UnityEngine.GameObject.Find("human_descr");
  1038.         UnityEngine.GameObject skills_descr = UnityEngine.GameObject.Find("skills_descr");
  1039.         human_descr.GetComponentInChildren<UILabel>().text = "已不再是新手了, 可以去xx领地刷boss。";
  1040.         skills_descr.GetComponentInChildren<UILabel>().text = "您可以去兽人洞穴击杀boss获得xx技能书来提升打击能力。";
  1041.        
  1042.         resetSelAvatar();
  1043.     }
  1044.  
  1045.     void on_selListItem3Click(UnityEngine.GameObject item)
  1046.     {
  1047.         currsel_selListItem = item.name;
  1048.         changeAvatarItem = 0;
  1049.        
  1050.         if(avatarList.Count > 0)
  1051.         {
  1052.             AvatarInfo info = avatarList[2];
  1053.             changeAvatarItem = info.roleType;
  1054.            
  1055.             Monitor.Enter(KBEngineApp.app.entities);
  1056.             Account account = (Account)KBEngineApp.app.player();
  1057.             Monitor.Enter(account.avatars);
  1058.             if((UInt64)account.getDefinedPropterty("lastSelCharacter") == 0)
  1059.                 account.setDefinedPropterty("lastSelCharacter", info.dbid);
  1060.             Monitor.Exit(KBEngineApp.app.entities);
  1061.         }
  1062.        
  1063.         selectSelListItemFocus(item);
  1064.        
  1065.         UnityEngine.GameObject human_descr = UnityEngine.GameObject.Find("human_descr");
  1066.         UnityEngine.GameObject skills_descr = UnityEngine.GameObject.Find("skills_descr");
  1067.         human_descr.GetComponentInChildren<UILabel>().text = "角色目前很强壮哦, 去竞技场和人pk刷排名吧。";
  1068.         skills_descr.GetComponentInChildren<UILabel>().text = "您的打击能力已经非常高了, 可以尝试提升防御等其他能力。";
  1069.        
  1070.         resetSelAvatar();
  1071.     }
  1072.  
  1073.     public void on_removeAvatarCanelClick(UnityEngine.GameObject obj)
  1074.     {
  1075.         UnityEngine.GameObject removeAvatarInput = UnityEngine.GameObject.Find("removeAvatarInputName");
  1076.         UnityEngine.GameObject removeavatarnameLabel = UnityEngine.GameObject.Find("removeavatarnameLabel");
  1077.         removeavatarnameLabel.GetComponent<UILabel>().text = "";
  1078.         Vector3 pos = removeAvatarInput.transform.localPosition;
  1079.         pos.y = 9999.0f;
  1080.         removeAvatarInput.transform.localPosition = pos;
  1081.         log_label.text = "";
  1082.     }
  1083.    
  1084.     public void on_removeAvatarOkClick(UnityEngine.GameObject obj)
  1085.     {
  1086.         UnityEngine.GameObject removeAvatarInput = UnityEngine.GameObject.Find("removeAvatarInputName");
  1087.         UnityEngine.GameObject removeavatarnameLabel = UnityEngine.GameObject.Find("removeavatarnameLabel");
  1088.        
  1089.         bool found = false;
  1090.         for(int i=0; i<avatarList.Count; i++)
  1091.         {
  1092.             AvatarInfo info = avatarList[i];
  1093.             if(info.name == removeavatarnameLabel.GetComponent<UILabel>().text)
  1094.             {
  1095.                 found = true;
  1096.                 break;
  1097.             }
  1098.         }
  1099.        
  1100.         if(found == false)
  1101.         {
  1102.             log_label.color = UnityEngine.Color.red;
  1103.             log_label.text = "没有找到该角色!";
  1104.             return;
  1105.         }
  1106.        
  1107.         Monitor.Enter(KBEngineApp.app.entities);
  1108.         Account account = (Account)KBEngineApp.app.player();
  1109.         account.reqRemoveAvatar(removeavatarnameLabel.GetComponent<UILabel>().text);
  1110.         Monitor.Exit(KBEngineApp.app.entities);
  1111.        
  1112.         on_removeAvatarCanelClick(obj);
  1113.     }
  1114.        
  1115.     public void onReqAvatarList(Dictionary<UInt64, Dictionary<string, object>> getAvatarList)
  1116.     {
  1117.         log_label.color = UnityEngine.Color.green;
  1118.         log_label.text = "";
  1119.            
  1120.         Monitor.Enter(KBEngineApp.app.entities);
  1121.         Account account = (Account)KBEngineApp.app.player();
  1122.         UInt64 lastSelCharacter = (UInt64)account.getDefinedPropterty("lastSelCharacter");
  1123.         Monitor.Exit(KBEngineApp.app.entities);
  1124.        
  1125.         List < string > loads = new List < string >();
  1126.         avatarList.Clear();
  1127.        
  1128.         Common.DEBUG_MSG("selavatar_ui::onReqAvatarList: " + getAvatarList.Count);
  1129.         showAvatars[0] = showAvatars[1] = showAvatars[2] = false;
  1130.        
  1131.         bool hasClickSelAvatar = false;
  1132.        
  1133.         if(getAvatarList.Count > 0)
  1134.         {
  1135.             int idx = 0;
  1136.             foreach(UInt64 dbid in getAvatarList.Keys)
  1137.             {
  1138.                 Dictionary<string, object> info = getAvatarList[dbid];
  1139.                 AvatarInfo ainfo;
  1140.                 ainfo.roleType = (Byte)info["roleType"];
  1141.                 ainfo.name = (string)info["name"];
  1142.                 ainfo.level = (UInt16)info["level"];
  1143.                 ainfo.dbid = (UInt64)info["dbid"];
  1144.                
  1145.                 showAvatars[idx++] = true;
  1146.  
  1147.                 if(lastSelCharacter == ainfo.dbid)
  1148.                 {
  1149.                     currsel_selListItem = "sel_list_item_focus" + idx;
  1150.                     on_selListItem1Click(UnityEngine.GameObject.Find(currsel_selListItem));
  1151.                     hasClickSelAvatar = true;
  1152.                 }
  1153.                
  1154.                 UnityEngine.GameObject sel_list_title = UnityEngine.GameObject.Find("sel_list_title" + idx);
  1155.                 sel_list_title.GetComponent<TextMesh>().text = avatarnames[(int)ainfo.roleType] + "\r\n" + ainfo.level + "级\r\n" + ainfo.name;
  1156.                
  1157.                 avatarList.Add(ainfo);
  1158.                
  1159.                 string loadRes = roleType2Srouce(ainfo.roleType);
  1160.                
  1161.                 if(loadRes != "")
  1162.                 {
  1163.                     bool found = false;
  1164.                     for(int ii=0; ii<loads.Count; ii++)
  1165.                     {
  1166.                         if(loads[ii] == loadRes)
  1167.                         {
  1168.                             found = true;
  1169.                             break;
  1170.                         }
  1171.                     }
  1172.                    
  1173.                     if(found == false)
  1174.                     {
  1175.                         loads.Add(loadRes);
  1176.                     }
  1177.                 }
  1178.             }
  1179.            
  1180.             if(hasClickSelAvatar == false)
  1181.             {
  1182.                 currsel_selListItem = "sel_list_item_focus1";
  1183.                 on_selListItem1Click(UnityEngine.GameObject.Find(currsel_selListItem));
  1184.             }
  1185.         }
  1186.         else
  1187.         {      
  1188.             log_label.color = UnityEngine.Color.red;
  1189.             log_label.text = "请创建一个角色!";
  1190.             on_gotocreateAvatarClick(null);
  1191.         }
  1192.        
  1193.         Monitor.Exit(account.avatars);
  1194.        
  1195.         loads.Add("avatar_wpgroup.unity3d");
  1196.        
  1197.         for(int i=0; i<loads.Count; i++)
  1198.         {
  1199.             string loadRes = loads[i];
  1200.             Asset asset = null;
  1201.            
  1202.             foreach(KeyValuePair<string, Asset> assetsCache in Scene.assetsCache)
  1203.             {
  1204.                 if(assetsCache.Value.source == loadRes)
  1205.                 {
  1206.                     asset = assetsCache.Value;
  1207.                     break;
  1208.                 }
  1209.             }
  1210.            
  1211.             if(asset == null)
  1212.             {
  1213.                 Common.ERROR_MSG("onReqAvatarList: not found asset " + loadRes);
  1214.                 continue;
  1215.             }
  1216.            
  1217.             asset.loadLevel = Asset.LOAD_LEVEL.LEVEL_ENTER_AFTER;
  1218.             if(i == 0 || getAvatarList.Count == 0)
  1219.                 asset.loadPri = 1;
  1220.            
  1221.             loader.inst.loadPool.addLoad(asset);
  1222.         }
  1223.        
  1224.         if(loads.Count > 0)
  1225.             loader.inst.loadPool.start();
  1226.        
  1227.         windowsize = 50;
  1228.         refreshAvatarListIcon();
  1229.     }
  1230.    
  1231.     private string roleType2Srouce(Byte type)
  1232.     {
  1233.         string loadRes = "";
  1234.         switch(type)
  1235.         {
  1236.             case 1:
  1237.                 loadRes = "avatar1.unity3d";
  1238.                 break;
  1239.             case 2:
  1240.                 loadRes = "avatar2.unity3d";
  1241.                 break;
  1242.             case 3:
  1243.                 loadRes = "avatar3.unity3d";
  1244.                 break;
  1245.             case 4:
  1246.                 loadRes = "avatar4.unity3d";
  1247.                 break;
  1248.             default:
  1249.                 Common.DEBUG_MSG("selavatar_ui::onReqAvatarList: roleType(" + type + ") is error!");
  1250.                 break;
  1251.         };
  1252.        
  1253.         return loadRes;
  1254.     }
  1255.  
  1256.     private Byte Srouce2roleType(string source)
  1257.     {
  1258.         if("avatar1.unity3d" == source)
  1259.             return 1;
  1260.  
  1261.         if("avatar2.unity3d" == source)
  1262.             return 2;
  1263.        
  1264.         if("avatar3.unity3d" == source)
  1265.             return 3;
  1266.        
  1267.         if("avatar4.unity3d" == source)
  1268.             return 4;
  1269.        
  1270.         return 0;
  1271.     }
  1272.    
  1273.     public void onCreateAvatarResult(Byte retcode, object info, Dictionary<UInt64, Dictionary<string, object>> avatarList)
  1274.     {
  1275.         if(retcode != 0)
  1276.         {
  1277.             log_label.color = UnityEngine.Color.red;
  1278.             log_label.text = "服务器返回错误:" + KBEngineApp.app.serverErr(retcode) + "!";
  1279.             return;
  1280.         }
  1281.        
  1282.         on_backClick(null);
  1283.         onReqAvatarList(avatarList);
  1284.     }
  1285.    
  1286.     public void onRemoveAvatar(UInt64 dbid)
  1287.     {
  1288.         if(dbid == 0)
  1289.         {
  1290.             log_label.color = UnityEngine.Color.red;
  1291.             log_label.text = "服务器删除角色返回错误!";
  1292.             return;
  1293.         }
  1294.  
  1295.         Monitor.Enter(KBEngineApp.app.entities);
  1296.         Account account = (Account)KBEngineApp.app.player();
  1297.         Monitor.Enter(account.avatars);
  1298.         Dictionary<UInt64, Dictionary<string, object>> avatars = account.avatars;
  1299.         Monitor.Exit(account.avatars);
  1300.         Monitor.Exit(KBEngineApp.app.entities);
  1301.  
  1302.         onReqAvatarList(avatars);
  1303.     }
  1304.    
  1305.     public void onAvatarEnterWorld(UInt64 rndUUID, Int32 eid, KBEngine.Avatar avatar)
  1306.     {
  1307.         log_label.color = UnityEngine.Color.green;
  1308.         log_label.text = "加载场景中...";
  1309.         KBEngine.Event.deregisterOut(this);
  1310.     }
  1311.    
  1312.     public void onDisableConnect()
  1313.     {
  1314.         log_label.color = UnityEngine.Color.red;
  1315.         log_label.text = "与服务器的连接已经中断!";
  1316.        
  1317.         InvokeRepeating("onDisableConnect_gobackToLogin", 3.0f, 0.1f);
  1318.     }
  1319.    
  1320.     void onDisableConnect_gobackToLogin()
  1321.     {
  1322.         CancelInvoke("onDisableConnect_gobackToLogin");
  1323.         on_backClick(null);
  1324.        
  1325.         if(isCreateMode == true)
  1326.             on_backClick(null);
  1327.     }
  1328. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement